r/learnpython • • Oct 23 '26

Python doesn't work in vc

I just want to

print("hello, world")

and it doesn't work

0 Upvotes

25 comments sorted by

5

u/Friendly-Repeat4854 Oct 23 '26

What Error Message did you receive ?
My Guess is your Python Interpreter propably isnt the correct one.

1

u/anas_mv Oct 23 '26

C:\Users\tec\AppData\Local\Python\pythoncore-3.15-64\python.exe: can't open file 'C:\Users\hello.py': [Errno 2] No such file or directory

8

u/TotoCodeFR Oct 23 '26

Because your file is saved somewhere else, maybe not even saved.

0

u/anas_mv Oct 23 '26

It's in home/tec

1

u/TotoCodeFR Oct 23 '26

Then you probably haven't went into the folder where the file is located. Type cd path\to\home\tec (obviously change the path to where the home/tec folder is actually found)

-1

u/anas_mv Oct 23 '26

cd\path\to\home\tec : The module 'cd' could not be loaded. For more information, run 'Import-Module cd'. At line:1 char:1

  • cd\path\to\home\tec
  •   + CategoryInfo          : ObjectNotFound: (cd\path\to\home\tec:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CouldNotAutoLoadModule

2

u/TotoCodeFR Oct 23 '26

You forgot the space between cd and the path and you need to change the path correctly

1

u/anas_mv Oct 23 '26

Still the same

2

u/TotoCodeFR Oct 23 '26

Go to file explorer. Navigate to the folder where your hello.py is located. Copy its path (I hope you know how to do so). Then, in the terminal, type "cd" (no quotes), a space, then paste your path. To paste, generally Ctrl+Shift+V works.

2

u/anas_mv Oct 23 '26

FINALLY Thank you bro

3

u/eruciform Oct 23 '26

where did you type it, how did you run it, and what message did you get, there's nowhere near enough information to debug this as is

-1

u/anas_mv Oct 23 '26

In the terminalIn the terminal, i write python hello , i got C:\Users\tec\AppData\Local\Python\pythoncore-3.15-64\python.exe: can't open file 'C:\Users\hello.py': [Errno 2] No such file or directory

3

u/eruciform Oct 23 '26

hello.py is not in your current directory of C:\Users\ so it can't find it

either move/save it there or change directory to where your hello.py is and rerun it there

0

u/anas_mv Oct 23 '26

How

2

u/eruciform Oct 23 '26

when you save the file you have to choose where it goes

or on the command line utilize "cd" (change directory) to change where you are

if you can't do either then you need to look up some tutorials on the tool you're using to save or on the command line terminal that you're using

1

u/JGhostThing Oct 23 '26

You need to be in the directory where the file hello.py is. Then "python hello" should work.

2

u/Outside_Complaint755 Oct 23 '26

When you invoke Python and tell it to run a script, you need to provide either the correct relative path to the script from your current working directory, or a full absolute path.

Let's say the script hello.py is in C:\Users\Me\Scripts\Test\hello.py

And let's say that when you launch the terminal, it opens to C:\Users\Me\ by default.

Then to run your script you can do one of the following:

# Option 1 - absolute path
Users\Me> python "C:\Users\Me\Scripts\Test\hello.py"

# Option 2 - relative path
Users\Me> python "Scripts\Test\hello.py"

# Option 3 - change working directory
# Then use new relative path
Users\Me> cd Scripts\Test
Users\Me\Scripts\Test> python hello.py

1

u/anas_mv Oct 23 '26

I don't have scripts only public and tec

1

u/Outside_Complaint755 Oct 23 '26

Its just an example. Adapt to your own directory structure

1

u/samuraisammich Oct 23 '26

Save the file first (there should be no dot next to the tab title at the top if the content of the file is saved)

1

u/ConcreteExist Oct 23 '26

So when you want to run a file with a program like python, you need to give it the actual path to the file.

1

u/andrewgarcia88 28d ago

double check the file is actually saved with a a .py extension and the quotes around hello world are straight quotes not curly ones, some editors autocorrect quotes which breaks the syntax

0

u/OlenaDoubleChecks Oct 23 '26

"vc" as in VS Code? Probably the interpreter isn't selected or Python isn't on PATH. What error do you get when you run it, and are you hitting the run button or typing in the terminal?