简体   繁体   中英

Python script won't run from the command line. It shows no error

I'm trying to run a simple Python Script on the CMD but nothing happens when I run it. I get no errors or anything. The py script is just a simple print ("Hello World").

All my.py files are in the Python/Projects file.

http://puu.sh/FFfJm/ee63955506.png

Just some context regarding this: I did install Python then Pycharm then Anaconda. I don't know if that has anything to do with conflicting Python files.

python isn't in your path. Checkout Adding directory to PATH Environment Variable in Windows , which is a good reference to the question of adding a variable to the path in CMD.

Are you sure you entered your command line query correctly?

python python_file_name.py

If you just entered your file_name.py it might have executed it but ended it simultaneously before you could see any result.

also try putting your file_name in double quotes.

If you have Python in PATH but script execution still doesn't work, inspect the C:\Users<user>\AppData\Local\Microsoft\WindowsApps folder.

There might be a zero-size python.exe file. It seems that this folder is earlier in PATH and zero-byte file intercept the console command execution. The microsoft store is opened with python page if I run that file. I removed this folder and python script start working again.

You also can ensure the correct python is available to the terminal with 'where python' to see the full path.

From your screenshot, you'd need to call

python "Hello World.py"

with quotes , not

python Hello World.py  // no, won't work

The reason is, when you don't include quotes around a filename with a space, it only takes the FIRST thing you wrote as the script name, the rest of the "words" are just passed as "command line arguments"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM