[英]Unable to Run .py script in command prompt
I know this is a super simple problem, but none of the other articles I have looked at have helped.我知道这是一个非常简单的问题,但我看过的其他文章都没有帮助。 I'm trying to run a hello.py file from command prompt and it is giving me this error message.
我正在尝试从命令提示符运行 hello.py 文件,它给了我这个错误消息。
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Users\Davidjb7>py hello.py
C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32\python.exe: can't open file 'hello.py': [Errno 2] No such file or directory
I really don't know why it is though, because hello.py is within the directory Python36-32, as shown here.我真的不知道为什么会这样,因为 hello.py 位于 Python36-32 目录中,如下所示。
C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32>dir
Volume in drive C is Windows8_OS
Volume Serial Number is DC59-907F
Directory of C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32
03/09/2017 04:06 PM <DIR> .
03/09/2017 04:06 PM <DIR> ..
02/26/2017 10:14 AM <DIR> DLLs
02/26/2017 10:14 AM <DIR> Doc
03/09/2017 04:05 PM 1,021 hello.py
02/26/2017 10:14 AM <DIR> include
02/26/2017 10:14 AM <DIR> Lib
02/26/2017 10:14 AM <DIR> libs
12/23/2016 07:25 AM 30,049 LICENSE.txt
12/23/2016 07:10 AM 258,657 NEWS.txt
03/09/2017 04:06 PM <DIR> python
12/23/2016 07:21 AM 97,944 python.exe
12/23/2016 07:19 AM 52,888 python3.dll
12/23/2016 07:18 AM 3,258,008 python36.dll
12/23/2016 07:22 AM 96,408 pythonw.exe
12/23/2016 07:10 AM 8,434 README.txt
02/26/2017 10:15 AM <DIR> Scripts
02/26/2017 10:14 AM <DIR> tcl
02/26/2017 10:14 AM <DIR> Tools
06/09/2016 10:46 PM 83,784 vcruntime140.dll
9 File(s) 3,887,193 bytes
11 Dir(s) 49,034,211,328 bytes free
C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32>
If someone could help me understand what I am doing wrong that would be awesome.如果有人能帮助我理解我做错了什么,那就太棒了。 And please be very clear in your descriptions, I'm not well versed.
请在您的描述中非常清楚,我不精通。 (Yet I hope)
(但我希望)
You have to run the python command in the directory that contains the file, or you must give the full path of the file.您必须在包含该文件的目录中运行 python 命令,或者您必须提供文件的完整路径。
If you wanted to run it as it was you would do:如果你想按原样运行它,你会这样做:
py C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32\hello.py
If you move the file into your current working directory when programming, you should just be able to run py hello.py.如果您在编程时将文件移动到当前工作目录中,您应该能够运行 py hello.py。
You could also try this:你也可以试试这个:
Checking this box resets file associations and fixes this problem for the command line.选中此框会重置文件关联并修复命令行的此问题。
The problem can arise again if you tell Windows to open up .py files in a text editor as default.如果您告诉 Windows 默认在文本编辑器中打开 .py 文件,则问题可能会再次出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.