简体   繁体   English

如何解决错误“'py.exe'不被识别为内部或外部命令,可操作程序或批处理文件”的错误?

[英]How to fix error “'py.exe' is not recognized as an internal or external command, operable program or batch file”?

I am very new to programming and I'm trying the self-taught route, so forgive me if I am asking the wrong questions, using this site incorrectly, or breaking formatting rules. 我是编程新手,正在尝试自学路线,因此,如果我提出了错误的问题,使用本网站的方式不正确或违反了格式设置规则,请原谅我。 I am using a course on Udemy to learn some Python basics for Windows 10. I have reached the part in my tutorial where I am learning about executing Python commands from the Command Prompt, and I am having some issues surrounding "py.exe". 我正在使用有关Udemy的课程来学习Windows 10的一些Python基础知识。在本教程中,我已经了解了如何从命令提示符处执行Python命令,并且在“ py.exe”方面遇到了一些问题。 Specifically the fact that it doesn't seem to exist on my PC. 特别是它在我的PC上似乎不存在的事实。

Every time that I try anything regarding "py.exe" I get the same error from the title. 每次我尝试任何与“ py.exe”有关的问题时,标题中都会出现相同的错误。 I have learned through many searches that this is supposed to be a file that comes included with your Python download, and that all it really does is search the .py file for a shebang so that it can call the proper version of Python to run whatever functions you have in your code. 我通过多次搜索了解到,这应该是您的Python下载文件随附的文件,而它真正要做的就是搜索.py文件中的shebang,以便它可以调用适当版本的Python来运行任何内容您的代码中具有的功能。 Fine, all of that makes sense. 很好,所有这些都是有道理的。 But the system doesn't have it anywhere. 但是系统没有任何地方。 I have done a file search of the whole computer and found nothing. 我已经对整个计算机进行了文件搜索,但没有发现任何问题。 I saw online that Python 3.7 saves the py.exe,pyw.exe, and pyshellext.amd64.dll files in C:\\Windows rather than the Python download folder, and I have found pyshellext.amd64.dll there (though I don't know what it does), but the other 2 are nowhere to be found. 我在网上看到Python 3.7将py.exe,pyw.exe和pyshellext.amd64.dll文件保存在C:\\ Windows中,而不是Python下载文件夹中,我在那里找到pyshellext.amd64.dll(尽管我没有)不知道该怎么做),但找不到其他2个。 My searches led me to believe that I must have messed something up on Install, so I have no uninstalled and reinstalled Python at least 4 times as administrator, and made sure that Python was added to the PATH. 我的搜索使我相信,我一定在Install上搞砸了,所以我没有至少4次以管理员身份卸载并重新安装Python,并确保将Python添加到PATH中。 Nothing I do seems to make any difference, which would make sense if my download just never had py.exe or pyw.exe to begin with. 我没有做任何事情,如果我的下载从未有py.exe或pyw.exe开始,那将是没有道理的。 However, when I call the command to test the association of .py file type, the Command Prompt seems to suggest that py.exe should be located in C:\\WINDOWS. 但是,当我调用该命令以测试.py文件类型的关联时,命令提示符似乎建议py.exe应该位于C:\\ WINDOWS中。 But when I look I can't find it. 但是当我看的时候我找不到。

C:\Users\Aaron>py.exe C:\users\aaron\mypythonscripts\Hellotest.py
'py.exe' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Aaron>assoc .py
.py=Python.File

C:\Users\Aaron>ftype Python.File
Python.File="C:\WINDOWS\py.exe" "%L" %*

Do I need to download some sort of stand alone version of py.exe or pyw.exe? 我需要下载某种独立版本的py.exe或pyw.exe吗? Is there some sort of new version of either of these commands that my tutorial is just too old to account for? 这些命令中是否有某种新版本的教程太旧而无法解释? Has anyone else ever seen this happen? 有没有其他人见过这种情况?

Thank you for taking the time to read! 感谢您抽出宝贵的时间阅读!

EDIT: I think there is something amiss with my install process. 编辑:我认为我的安装过程有些不对劲。 I have done a file search from the command prompt and found nothing 我已经从命令提示符处进行了文件搜索,但未发现任何内容

C:\Users\Aaron> where py.exe
INFO: Could not find files for the given pattern(s)

I have tried uninstalling and reinstalling (for the 8th time) and I see the box many people have referenced that includes the py launcher with the download. 我尝试了卸载和重新安装(第8次),我看到许多人引用的框,其中包含带有下载的py启动器。 It is greyed out but checked, so I assume it should be downloading with the rest of the package, but I can't find it. 它显示为灰色,但已选中,因此我认为它应该与软件包的其余部分一起下载,但我找不到它。

Here is a screenshot of my installer 这是我的安装程序的屏幕截图

Could the piece I have highlighted be causing me issues? 我突出显示的那篇文章会导致我遇到问题吗? It seems to imply that my system is removing the py launcher? 似乎暗示我的系统正在删除py启动器?

Your python executable seems not to be into the %PATH% variable of your operating system. 您的python可执行文件似乎没有放入操作系统的%PATH%变量中。
You have two possibilities : 您有两种可能性:
Add the python executable path to the %PATH% 将python可执行文件路径添加到%PATH%
Explicitely launch python from the C: like C:\\System32\\python2.7\\python.exe or something like that depending of where it is on your system. C:显式启动python,例如C:\\System32\\python2.7\\python.exe或类似的东西,具体取决于它在系统上的位置。
Have you installed python from the .exe on the official website ? 您是否已从官方网站上的.exe安装了python?

I wanted to add a detailed answer for anyone that stumbles into the same situation as me in the future. 我想为以后遇到与我相同情况的任何人添加详细答案。

BE CAREFUL WITH YOUR INSTALL. 小心安装。 The root of all of my issues came from doing the initial download incorrectly. 我所有问题的根源都在于错误地进行了初始下载。 If, like me, you pick a tutorial that "skips most of the computer science stuff" just know that this is not a shortcut. 如果像我一样,您选择的教程“跳过了大多数计算机科学知识”,只是知道这不是捷径。 It is an announcing that you will have to teach the "computer science stuff" to yourself instead. 宣布您将不得不向自己教授“计算机科学知识”。 It's becoming obvious quite quickly that there is no way to skip the "computer science stuff" if you want to actually understand what you are doing. 很快就变得很明显,如果您想真正了解自己在做什么,就没有办法跳过“计算机科学知识”。

My final solution was to uninstall anything remotely related to Python out of the entire system (as opposed to just the version that I was working in), and then reinstall the correct version while following the instructions of someone who did it correctly the first time. 我的最终解决方案是从整个系统中卸载与Python远程相关的所有内容(而不是仅使用我正在使用的版本),然后按照首次正确执行操作的人员的指示重新安装正确的版本。 In retrospect it seems very obvious that trying to troubleshoot a process that Python is meant to do automatically is a way to waste time and energy, but it was also a great way to learn unnecessary lessons! 回顾过去,似乎很显然,尝试对Python打算自动执行的过程进行故障排除是浪费时间和精力的一种方式,但这也是学习不必要的课程的好方法!

TL;DR In the beginning, don't assume you did anything the right way. TL; DR刚开始时,不要以为您做对了。 Including install (and uninstall. and reinstall. and uninstall again. and reinstall again. and uninstall again, etc.) 包括安装(然后卸载。然后重新安装。然后再次卸载。然后重新安装。然后再次卸载,等等)。

https://docs.python.org/2/faq/windows.html https://docs.python.org/2/faq/windows.html

If the python command, instead of displaying the interpreter prompt >>>, gives you a message like: 如果python命令没有显示解释器提示>>>,而是显示如下消息:

'python' is not recognized as an internal or external command, operable program or batch file.

or: 要么:

Bad command or filename

Then you need to make sure that your computer knows where to find the Python interpreter. 然后,您需要确保您的计算机知道在哪里可以找到Python解释器。 To do this you will have to modify a setting called PATH, which is a list of directories where Windows will look for programs. 为此,您将必须修改名为PATH的设置,该设置是Windows将在其中查找程序的目录的列表。

Or try a reinstall, see last comment below: 或尝试重新安装,请参见下面的最新评论:

From docs.python.org/3/using/windows.html: 从docs.python.org/3/using/windows.html:
To install the Python Launcher for Windows for all users) [...] The Python Launcher for Windows will be installed according to the option at the bottom of the first page. 要为所有用户安装Windows版Python Launcher,请按照首页底部的选项安装Windows版Python Launcher。
And, docs.python.org/3/using/windows.html#launcher states 而且,docs.python.org/3/using/windows.html#launcher状态
that the error ''py' is not recognized as an internal or external command, operable program or batch file.' 错误“ py”未被识别为内部或外部命令,可操作程序或批处理文件。 comes from the fact that per-user installations of Python do not add the launcher to PATH unless the option was selected on installation. 源自以下事实:除非在安装时选择了该选项,否则按用户安装Python不会将启动器添加到PATH中。

Maybe a reinstall helps this time! 也许这次重新安装会有所帮助!

暂无
暂无

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

相关问题 如何修复“auto-py-to-exe”不被识别为内部或外部命令、可运行程序或批处理文件 - how to fix 'auto-py-to-exe' is not recognized as an internal or external command, operable program or batch file 如何修复“py”未被识别为内部或外部命令、可运行程序或批处理文件 - How to fix 'py' is not recognized as an internal or external command, operable program or batch file 如何修复错误:“make”不是内部或外部命令、可运行程序或批处理文件 - How to fix error : 'make' is not recognized as an internal or external command, operable program or batch file py 未被识别为内部或外部可运行程序或批处理文件 - py is not recognized as an internal or external operable program or batch file 'command' 不是内部或外部命令,也不是可运行的程序 或批处理文件 - 'command' is not recognized as an internal or external command, operable program or batch file 'c:\Program' 不是内部或外部命令,也不是可运行的程序或批处理文件 - 'c:\Program' is not recognized as an internal or external command, operable program or batch file 无法将pycrypto'chmod'的setup.py install运行为内部或外部命令,可操作程序或批处理文件 - Running setup.py install for pycrypto 'chmod' is not recognized as an internal or external command, operable program or batch file 'py.test' 不是内部或外部命令,也不是可运行的程序或批处理文件 - 'py.test' is not recognized as an internal or external command, operable program or batch file 'pip3' 不是内部或外部命令,也不是可运行的程序或批处理文件 - 'pip3' is not recognized as an internal or external command, operable program or batch file 'pip'不被识别为内部或外部命令,可操作程序或批处理文件 - 'pip' is not recognized as an internal or external command, operable program or batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM