r/learnpython • • 4h ago

About running python code in terminal

Guys, I am beginner. I have the python code and have saved in file. Now I want to place the file path in the terminal and run that code. I don't know what should I write before adding the file path? Please help!

4 Upvotes

16 comments sorted by

2

u/Entire_Ad_6447 4h ago

Do you have python installed?

1

u/South-Put-7948 4h ago

I have anaconda installed

2

u/Entire_Ad_6447 4h ago

Okay then it should be python or python3 /PathTo where the code is/name of the .py file. You want to run.

1

u/South-Put-7948 3h ago

Thank you It worked

1

u/Adbelhak_Unsicker 2h ago

classic step zero right here

1

u/PonkMcSquiggles 4h ago

Assuming that you have Python installed and in your path, the command for running a Python file is just

python [path to file]

1

u/South-Put-7948 3h ago

Thank you so much It worked. I realized that my box folder wasen't synced thats why the file wasn't running in the terminal, but it got fixed.

1

u/avalexva 4h ago

Hey!
what your system?
Windows

Open Command Prompt or PowerShell, then:

python DISKNAME:\path\to\your\script.py

or for mac and linux

python /path/to/your/script.py

or open you provider in dir with your file, and right click + shift (this for windows) "run powershell here"

1

u/South-Put-7948 3h ago

Thank you so much It worked

1

u/socal_nerdtastic 4h ago

for mac and linux it needs to be python3, unless you have a venv activated.

(I know the PSF recommends using python but afaik only 1 linux distro follows that)

1

u/South-Put-7948 3h ago

Thank you so much, Yaa it was in Mac and Python3 made it work

1

u/avalexva 3h ago

Yes, that’s true—you don’t often type that out in an IDE.

1

u/Due-Mortgage-6854 4h ago

python or python3 or py followed by your PATH/file.py

2

u/South-Put-7948 3h ago

Thank you it worked

1

u/EszterSantos72 4h ago

Type python3 before your file path, like python3 myscript.py. On some systems just python works, but if you have both Python 2 and 3 installed, python3 makes sure you run the right version.

1

u/South-Put-7948 3h ago

Thank you so much it worked.