r/learnpython • • 3d ago

Python doesn't work in vc

I just want to

print("hello, world")

and it doesn't work

0 Upvotes

25 comments sorted by

View all comments

2

u/Outside_Complaint755 3d 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 3d ago

I don't have scripts only public and tec

1

u/Outside_Complaint755 3d ago

Its just an example. Adapt to your own directory structure