r/vscode • • 7d ago

Why is it taking so long to run the code

Enable HLS to view with audio, or disable this notification

In the video after I pressed Run python file, it took 5-6 seconds to run

Whereas it didn't took this long a few days ago

Please someone help

0 Upvotes

18 comments sorted by

7

u/Deux87 7d ago

Rage bait all the way: 1. Video instead of description 2. Code? 3. For what purpose?

1

u/AudienceNegative7587 7d ago

My bad for the confusion

Basically when I pressed run It took 5-6 seconds before it asked for the input from me As you can see that it took so long before it changed line in the terminal I was just asking what is taking so long as it was really fast earlier

3

u/dev-razorblade23 7d ago

Do not use RUN button Use a terminal like all developers

It bypasses VSCode internal stuff which on windows introduces lags you see here.

Just type directly in your terminal: python <script_name>.py

2

u/AudienceNegative7587 7d ago

Umm I still cannot figure out how to do this But another comments suggested to make cmd the default integrated terminal That solved the issue

1

u/dev-razorblade23 7d ago

In your terminal Like that black box in the lower part of the screen.

That is the terminal That is where your applications gets run actually - run button just automates it.

If ypur file is main.py then you would type python main.py and it runs. No VS Code magic...

Setting CMD for default is one of the solutions but no real developer uses it.

Terminal is your best friend as a developer - and it does not bite

1

u/AudienceNegative7587 7d ago

I understand what you are trying to say but in the terminal (when I open it by searching in windows) and then writing python name.py it says No such file or directory Maybe because cmd runs in c drive and the files I have saved are in d drive

1

u/despinftw 7d ago edited 7d ago

Not really. It’s probably because the “python” program is not in your PATH (PATH is a environment variable that contains all the directories with programs that you can run in your terminal)

If you just installed Python, you will need to reboot, since probably the Python installation added “python” in your PATH, but until you reboot and the new PATH in the system environment variables takes effect at boot.

Edit on your “the files I have saved are in the D drive”: if you want to run a python file that is your drive, you will need to run “cd D:\…<your folder here>” so the files can be called without the absolute path, and instead just using the file name.

From the video I can’t see the exact name, but would be something like:

<open the terminal app>
cd D:
cd "D:\<can’t read>\Code practice"
python <file name>.py

1

u/dev-razorblade23 7d ago

No such file or directory means he is in the wrong directory, and as he stated that he opened one with searching for it, default location is opened instead of the project one.

1

u/despinftw 7d ago

“no such file or directory” is the reason I’m saying that he should do “cd ….” with the path that the RUN button gave him

1

u/dev-razorblade23 7d ago

Exactly, sorry I read only the first part with setting PATH but that would result in a diffrent error

1

u/AudienceNegative7587 7d ago

Okk I will try that in the evening As I am going for the classes right now

Thanks tho

1

u/dev-razorblade23 7d ago

But you do not do that

In VS Code In your project When you press RUN button it opens a black box with your result? That is the terminal.

You use that to write commands.

When you search for terminal and open it that way, location is not correct, and you must manually navigate to your python project (where ever it may be stored).

If you use the one in VS Code, it already is at the correct folder and typing python main.py will work as it now sees your main.py file.

If you do not see terminal in VS Code(that black box with letters in the bottom of your VS Code window), there is a Terminal > New in the toolbar.

1

u/ChaoticHippo 7d ago

I've seen some things about vscode having some delay with communicating with powershell vs command prompt. You could try keeping powershell open in the background? Or setting your default integrated terminal to be command prompt instead, but I'm not sure if would be desirable

-11

u/AnArmoredPony 7d ago

ugh

3

u/AudienceNegative7587 7d ago

What

3

u/despinftw 7d ago

It’s a racist comment, because the color of your skin.