即使在添加到 PATH 后,Windows CMD 中也无法识别 python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24186823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python not recognized in Windows CMD even after adding to PATH
提问by jeff
I'm trying to -learn to write and- run Python scripts on my Windows 7 64 bit machine. I installed Python in C:/Python34, and I added this to my Windows' PATH variable :
我正在尝试 - 学习在我的 Windows 7 64 位机器上编写和运行 Python 脚本。我在 C:/Python34 中安装了 Python,并将其添加到 Windows 的 PATH 变量中:
C:\Python34; C:\Python34\python.exe
(the second one is probably meaningless but I tried) and still I get this error in Windows command line :
(第二个可能毫无意义,但我试过了)但我仍然在 Windows 命令行中收到此错误:
C:\Users\me>python test.py
'python' is not recognized as an internal or external command,
operable program or batch file.
So how do I truly install Python on my Windows x64 machine ?
那么如何在我的 Windows x64 机器上真正安装 Python 呢?
回答by yossim
This might be trivial, but have you tried closing your command line window and opening a new one? This is supposed to reload all the environment variables. Try typing
这可能是微不足道的,但是您是否尝试过关闭命令行窗口并打开一个新窗口?这应该重新加载所有环境变量。尝试打字
echo %PATH%
into the command prompt and see if you can find your Python directory there.
进入命令提示符,看看你是否能在那里找到你的 Python 目录。
Also, the second part of your addition to the PATH environment variable is indeed unnecessary.
此外,您添加到 PATH 环境变量的第二部分确实是不必要的。
回答by bcorso
Environment PATH Length Limitation is 1024 characters
环境路径长度限制为 1024 个字符
If restarting your cmdwindow does not work you might have reached the character limit for PATH, which is a surprisingly short 1024characters.
如果重新启动您的cmd窗口不起作用,您可能已经达到PATH的字符限制,这是一个令人惊讶的短1024 个字符。
Note that the user interface will happily allows you to define a PATH that is way longer than 1024, and will just truncate anything longer than this. Use
请注意,用户界面很乐意允许您定义一个比 1024 长得多的 PATH,并且只会截断比这更长的任何内容。用
echo %PATH%
in your cmd window to see if the PATH being truncated.
在您的 cmd 窗口中查看 PATH 是否被截断。
Solution
解决方案
Unfortunately, there is no good way to fix this besides removing something else from your PATH.
不幸的是,除了从PATH 中删除其他内容之外,没有其他好的方法可以解决此问题。
NOTE:Your PATH = SYSTEM_PATH + USER_PATH, so you need to make sure the combined is < 1024.
注意:您的PATH = SYSTEM_PATH + USER_PATH,因此您需要确保组合小于 1024。
回答by maulynvia
I spent sometime checking and rechecking the path and restarting to no avail.
我花了一些时间检查并重新检查路径并重新启动无济于事。
The only thing that worked for me was to rename the executable C:\Python34\python.exe to C:\Python34\python34.exe. This way, calling typing python34 at the command line now works.
唯一对我有用的是将可执行文件 C:\Python34\python.exe 重命名为 C:\Python34\python 34.exe。这样,现在可以在命令行调用输入 python34 了。
On windows it seems that when calling 'python', the system finds C:\Python27 in the path before it finds C:\Python34
在 Windows 上,似乎在调用 'python' 时,系统会在找到 C:\Python34 之前在路径中找到 C:\Python27
I'm not sure if this is the right way to do this, seems like a hack, but it seems to work OK.
我不确定这是否是正确的方法,看起来像一个黑客,但它似乎工作正常。
回答by David Schilpp
I'm late to the game here, but I'd like to share my solution for future users. The previous answers were on the right track, but if you do not open the CMD as an administrator, then you will be thrown that same error. I know this seems trivial and obvious, but after spending the past 8 hours programming before attempting to install Django for the first time, you might be surprised at the stupid mistakes you might make.
我在这里玩游戏很晚,但我想为未来的用户分享我的解决方案。以前的答案是正确的,但是如果您没有以管理员身份打开 CMD,那么您将抛出同样的错误。我知道这看起来微不足道而且显而易见,但是在第一次尝试安装 Django 之前花费了过去 8 个小时的编程时间之后,您可能会对自己可能犯的愚蠢错误感到惊讶。
回答by senis000
I had the same problem: python not being recognized, with python in the path which was was not truncated.
我遇到了同样的问题:python 未被识别,python 在未被截断的路径中。
Following the comment of eryksun in yossim's answer:
按照 eryksun 在 yossim 的回答中的评论:
Also, if you installed for all users you should have %SystemRoot%\py.exe, which >is typically C:\Windows\py.exe. So without setting Python's directory in PATH >you can simply run py to start Python; if 2.x is installed use py -3 since >Python 2 is the default. – eryksun
此外,如果您为所有用户安装了 %SystemRoot%\py.exe,通常是 C:\Windows\py.exe。因此,无需在 PATH 中设置 Python 的目录,您只需运行 py 即可启动 Python;如果安装了 2.x,请使用 py -3 因为 >Python 2 是默认值。– 埃克森
I tried to use py instead of python and it worked. Meaning: python setup.py build -> does NOT work. py setup.py build -> does work. Hope it helps
我尝试使用 py 而不是 python 并且它起作用了。含义:python setup.py build -> 不起作用。py setup.py build -> 确实有效。希望能帮助到你
回答by nihal111
Also, make sure to leave no spaces after the semi-colon.
另外,请确保分号后没有空格。
For example, this didn't work for me:
C:\Windows\system32; C:\Python27; C:\Python27\Scripts;
例如,这对我不起作用:
C:\Windows\system32; C:\Python27; C:\Python27\Scripts;
But, this did:
C:\Windows\system32;C:\Python27;C:\Python27\Scripts;
但是,这样做了:
C:\Windows\system32;C:\Python27;C:\Python27\Scripts;
回答by Arnab Roy
I was also having the same problem.
我也遇到了同样的问题。
Turns out the path I added included '..\python.exe' at the end, which as turns out was not required. I only needed to add the directory in which 'python.exe' is in (which in my case is the Anaconda's distribution directory in Users folder), similar to what we do when installing JDK in our system's PATH variable.
原来我添加的路径在末尾包含 '..\python.exe' ,事实证明这不是必需的。我只需要添加'python.exe'所在的目录(在我的例子中是用户文件夹中Anaconda的分发目录),类似于我们在系统的PATH变量中安装JDK时所做的。
Hope it helps!
希望能帮助到你!
回答by Nick W
I had the same issue with Python 2.7 on Windows 10 until I changed the file path in Enviroment Variables to the folder path, ie C:\Python27\python.exe
didn't work but C:\Python27\
did work.
我在 Windows 10 上使用 Python 2.7 遇到了同样的问题,直到我将环境变量中的文件路径更改为文件夹路径,即C:\Python27\python.exe
没有工作但C:\Python27\
确实有效。
回答by dev ip
For me, installing the 'Windows x86-64 executable installer' from the official python portal did the trick.
对我来说,从官方 python 门户安装“Windows x86-64 可执行安装程序”就成功了。
Python interpreter was not initially recognized, while i had installed 32 bit python. Uninstalled python 32 bit and installed 64 bit.
Python 解释器最初未被识别,而我已经安装了 32 位 Python。卸载python 32位并安装64位。
So, if you are on a x-64 processor, install 64bit python.
因此,如果您使用的是 x-64 处理器,请安装 64 位 python。
回答by mindmischief
I tried it multiple times with the default installer option, the first one, (Python 3.7.3) with both 'add to environment variable' and 'all users' checked, though the latter was greyed out and couldn't be unchecked.
我使用默认安装程序选项(第一个选项)(Python 3.7.3)尝试了多次,同时选中了“添加到环境变量”和“所有用户”,尽管后者显示为灰色且无法取消选中。
It failed to work for other users except for the user I installed it under until I uninstalled it and chose "Custom Install". It then clearly showed the install path being in the C:\Program Files\Python37 directory when it was failing to install it there the other way even though the 'All Users' option was checked.
除了我安装它的用户之外,它无法为其他用户工作,直到我卸载它并选择“自定义安装”。然后它清楚地显示安装路径在 C:\Program Files\Python37 目录中,即使选中了“所有用户”选项,它也无法以其他方式安装它。