简体   繁体   English

Python 脚本不会从命令行运行。 它显示没有错误

[英]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.我正在尝试在 CMD 上运行一个简单的 Python 脚本,但是运行它时没有任何反应。 I get no errors or anything.我没有得到任何错误或任何东西。 The py script is just a simple print ("Hello World"). py 脚本只是一个简单的打印(“Hello World”)。

All my.py files are in the Python/Projects file.所有 my.py 文件都在 Python/Projects 文件中。

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

Just some context regarding this: I did install Python then Pycharm then Anaconda.关于此的一些上下文:我确实安装了 Python 然后 Pycharm 然后 Anaconda。 I don't know if that has anything to do with conflicting Python files.我不知道这是否与 Python 文件冲突有关。

python isn't in your path. python不在您的路径中。 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.出在 Windows 中将目录添加到 PATH 环境变量,这是对 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.如果您刚刚输入了file_name.py ,它可能已经执行了它,但在您看到任何结果之前同时结束了它。

also try putting your file_name in double quotes.还可以尝试将您的 file_name 放在双引号中。

If you have Python in PATH but script execution still doesn't work, inspect the C:\Users<user>\AppData\Local\Microsoft\WindowsApps folder.如果您在 PATH 中有 Python 但脚本执行仍然不起作用,请检查 C:\Users<user>\AppData\Local\Microsoft\WindowsApps 文件夹。

There might be a zero-size python.exe file.可能存在一个大小为零的 python.exe 文件。 It seems that this folder is earlier in PATH and zero-byte file intercept the console command execution.似乎这个文件夹在 PATH 中较早,并且零字节文件拦截了控制台命令的执行。 The microsoft store is opened with python page if I run that file.如果我运行该文件,Microsoft 商店将使用 python 页面打开。 I removed this folder and python script start working again.我删除了这个文件夹,python 脚本再次开始工作。

You also can ensure the correct python is available to the terminal with 'where python' to see the full path.您还可以使用“where python”确保终端可以使用正确的 python 以查看完整路径。

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"原因是,当您不在带空格的文件名周围包含引号时,它只会将您写的第一件事作为脚本名称,“单词”的 rest 只是作为“命令行参数”传递

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python脚本不会从命令行运行,但是在以“ python”开头时会运行 - python script won't run from command line but will when preceded by 'python' 从Windows命令行运行脚本时,由于“ SQL语句正在进行”,Python sqlite3无法回滚事务。 - Python sqlite3 cannot rollback transaction due to 'SQL statements in progress' when script run from Windows command line. Python ConfigParser无法从命令行运行 - Python ConfigParser won't run from command line 如何运行一条简单但较长的python行。 从蝙蝠?,py脚本? 要不然是啥 - How to run a simple but long python line. From bat?, py script? or what 从命令行运行 python 脚本时未找到模块错误 - module not found error when python script is run from command line 直接从命令行运行 python 脚本 - run python script directly from command line Python 脚本不会像 cgi 一样播放声音,而是通过命令行播放 - Python script won't play sound as cgi, but via command line python子进程不会运行phantomjs,但可以在linux命令行中使用 - python subprocess won't run phantomjs, but works in linux command line Scrapy 已安装,但不会从命令行运行 - Scrapy installed, but won't run from the command line 如何从命令行或其他脚本运行 python 脚本 - How to run python script from command line or from another script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM