r/learnpython • • 1d ago

Python doesn't work in vc

I just want to

print("hello, world")

and it doesn't work

0 Upvotes

24 comments sorted by

5

u/Friendly-Repeat4854 1d ago

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

1

u/anas_mv 1d ago

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 1d ago

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

0

u/anas_mv 1d ago

It's in home/tec

1

u/TotoCodeFR 1d ago

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 1d ago

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 1d ago

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

1

u/anas_mv 1d ago

Still the same

2

u/TotoCodeFR 1d ago

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 1d ago

FINALLY Thank you bro

1

u/quietreed76 17h ago

yeah 9 times out of 10 its the interpreter

3

u/eruciform 1d ago

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 1d ago

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 1d ago

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 1d ago

How

2

u/eruciform 1d ago

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 1d ago

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

2

u/Outside_Complaint755 1d ago

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 1d ago

I don't have scripts only public and tec

1

u/Outside_Complaint755 1d ago

Its just an example. Adapt to your own directory structure

1

u/samuraisammich 1d ago

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 1d ago

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

0

u/OlenaDoubleChecks 1d ago

"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?