简体   繁体   English

python不被识别为内部或外部命令

[英]python is not recognised as an internal or external command

This is a really annoying problem. 这是一个非常烦人的问题。 I've prowled the web for solutions, but all I found was tips about changing the PATH variable, which I did, of course. 我已经在网上寻找解决方案,但我发现的只是改变PATH变量的提示,当然,我做了。 My Python install directory is C:\\Python27. 我的Python安装目录是C:\\ Python27。 It' a 32 bit version. 它是一个32位版本。 Whenever I type python in the command prompt, it says that it isn't recognised as an internal or external command. 每当我在命令提示符下键入python时,它都表示它不被识别为内部或外部命令。 Currently, my PATH variable is set to C:\\Python27;C:\\Python27\\Lib\\site-packages\\;C:\\Python27\\Scripts. 目前,我的PATH变量设置为C:\\ Python27; C:\\ Python27 \\ Lib \\ site-packages \\; C:\\ Python27 \\ Scripts。 Anyone has any ideas? 有人有什么想法吗? I run Windows 7 by the way (64 bit). 我顺便运行Windows 7(64位)。 I'm pretty desperate. 我非常绝望。 Heck, if nothing works I guess I'll try dual-booting Linux and Windows 7... 哎呀,如果什么都行不通,我想我会尝试双启动Linux和Windows 7 ......

Just adding the Python path and trying again worked for me (without reboot). 只需添加Python路径并再次尝试为我工作(无需重启)。

MS-dos command for Python 2.7: Python 2.7的MS-dos命令:

set PATH=%PATH%;C:\python27\

MS-dos command for Python 3.3: Python 3.3的MS-dos命令:

set PATH=%PATH%;C:\python33\

(check if that is the folder where you installed Python). (检查这是否是您安装Python的文件夹)。

Quick fix: May not be the most elegant or long term fix but if you are really frustrated and just want to get it to run, just copy paste the python.exe file to your current directory. 快速修复:可能不是最优雅或长期的修复,但如果您真的感到沮丧并且只想让它运行,只需将python.exe文件复制粘贴到当前目录即可。 This worked for me. 这对我有用。

After changing the PATH variable in windows, you need to reboot your system before it takes effect. 在Windows中更改PATH变量后,需要重新启动系统才能生效。

Edit: As stated by @tdelaney, only a restart of cmd.exe should be required. 编辑:正如@tdelaney所述,只需要重新启动cmd.exe。 This is true atleast for Windows 7 64bit. 这至少适用于Windows 7 64位。

After adding the python folder to the system PATH variable, you should reboot your computer. 将python文件夹添加到系统PATH变量后,您应该重新启动计算机。

Another simple solution is: create a shortcut of the python.exe executable (probably it is in C:\\Python27\\python.exe , or similar) in a place like C:\\Windows\\system32 (that is, a place that already is listed in the PATH variable). 另一个简单的解决方案是:在C:\\Windows\\system32这样的地方创建python.exe可执行文件的快捷方式(可能是在C:\\Python27\\python.exe ,或者类似)(也就是说,已经存在的地方)列在PATH变量中)。 The name of your shortcut should be python (maybe python.exe should work too). 你的快捷方式的名称应该是python (也许python.exe应该工作)。 I mean, it can't be python - shortcut or similar, for your purposes. 我的意思是,它不能是python - shortcut或类似的,为了你的目的。

To see the contents of the PATH variable, go to the cmd and enter set PATH . 要查看PATH变量的内容,请转到cmd并输入set PATH

In your PATH have you got a leading space before your Python path? 在您的PATH中,您在Python路径之前有一个领先的空间吗?

For example: 例如:

"C:\somedirectory\bin; C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts"

If you have a leading space between path's "ry\\bin; C:\\Pyt" , it won't work and is usually the cause for this type of issue. 如果路径的"ry\\bin; C:\\Pyt"之间有一个前导空格,它将无法工作,通常是导致此类问题的原因。

When installing, there is a checkbox that is by default not selected, but it asks to add python to the environment variable. 安装时,默认情况下没有选中复选框,但它要求将python添加到环境变量中。 Re-install and check that box. 重新安装并检查该框。

I'd rather the installer do it than struggle in the weeds myself. 我宁愿安装人员这样做而不是自己在杂草中挣扎。

好的,正如你说你的Python安装目录是C:\\ Python27,打开我的电脑,然后打开c:驱动器,如果你没有看到“Python27”命名文件夹,那么尝试使用搜索选项搜索它,(在我的情况下)我发现它在old.window文件夹中,不知道它是如何移动的那样)在c盘中剪切并将其与文件夹一样,程序文件,用户等...,现在打开cmd并键入python并按Enter键进行检查如果现在有效,

This is only a partial answer, but I found (repeatedly) that I'd have similar issues when I would use the gui installer and not go through the custom setup. 这只是一个部分答案,但我发现(反复)当我使用gui安装程序而不通过自定义设置时,我会遇到类似的问题。

Using the custom setup option, then using the same settings, the "install for all users" (that then installs to C://python.version/blah instead of the user based default structure) WOULD allow the installer to setup PATH correctly. 使用自定义安装选项,然后使用相同的设置,“为所有用户安装”(然后安装到C://python.version/blah而不是基于用户的默认结构)将允许安装程序正确设置PATH。

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

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