r/learnpython • • 38m 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!

2 Upvotes

8 comments sorted by

•

u/Entire_Ad_6447 36m ago

Do you have python installed?

•

u/South-Put-7948 27m ago

I have anaconda installed

•

u/Entire_Ad_6447 26m ago

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

•

u/PonkMcSquiggles 35m ago

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

python [path to file]

•

u/avalexva 7m 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"

•

u/socal_nerdtastic 0m ago

for mac and linux it needs to be python3

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

•

u/Due-Mortgage-6854 7m ago

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

•

u/EszterSantos72 4m 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.