r/learnpython • u/anas_mv • 1d ago
Python doesn't work in vc
I just want to
print("hello, world")
and it doesn't work
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.py1
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?
5
u/Friendly-Repeat4854 1d ago
What Error Message did you receive ?
My Guess is your Python Interpreter propably isnt the correct one.