'python' 未被识别为内部或外部命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17953124/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:34:10  来源:igfitidea点击:

'python' is not recognized as an internal or external command

pythoncmd

提问by Dave Stallberg

So I have recently installed Python Version 2.7.5 and I have made a little loop thing with it but the problem is, when I go to cmd and type python testloop.pyI get the error:

所以我最近安装了 Python 2.7.5 版,我用它做了一些循环,但问题是,当我转到 cmd 并键入时,python testloop.py我收到错误:

'python' is not recognized as an internal or external command

'python' 未被识别为内部或外部命令

I have tried setting the path but no avail.

我试过设置路径但无济于事。

Here is my path:

这是我的路径:

C:\Program Files\Python27

C:\Program Files\Python27

As you can see, this is where my Python is installed. I don't know what else to do. Can someone help?

如您所见,这是安装我的 Python 的地方。我不知道还能做什么。有人可以帮忙吗?

采纳答案by Darrell O'Donnell

You need to add that folder to your Windows Path:

您需要将该文件夹添加到您的 Windows 路径:

https://docs.python.org/2/using/windows.htmlTaken from this question.

https://docs.python.org/2/using/windows.html取自这个问题。

回答by iheanyi

From the Python docs, set the PATH like you did as above.

从 Python文档中,像上面一样设置 PATH。

You should arrange for Python's installation directory to be added to the PATH of every command window as it starts. If you installed Python fairly recently then the command dir C:\py* will probably tell you where it is installed; the usual location is something like C:\Python27. Otherwise you will be reduced to a search of your whole disk

Use Tools ? Find or hit the Search button and look for “python.exe”. Supposing you discover that Python is installed in the C:\Python27 directory (the default at the time of writing), you should make sure that entering the command

您应该安排将 Python 的安装目录添加到每个命令窗口启动时的 PATH 中。如果你最近安装了 Python,那么命令 dir C:\py* 可能会告诉你它的安装位置;通常的位置类似于 C:\Python27。否则,您将只能搜索整个磁盘

使用工具?查找或点击“搜索”按钮并查找“python.exe”。假设你发现 Python 安装在 C:\Python27 目录下(写作时的默认目录),你应该确保输入命令

Then execute the Python command using the full path name to make sure that works.

然后使用完整路径名执行 Python 命令以确保其有效。

回答by Asif Iqbal

Try "py" instead of "python" from command line:

从命令行尝试“py”而不是“python”:

C:\Users\Cpsa>py
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

C:\Users\Cpsa>py
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 输入
“help”,“copyright” 、“信用”或“许可证”以获取更多信息。
>>>

回答by snr

Firstly, be sure where your python directory. It is normally in C:\Python27. If yours is different then change it from the below command.

首先,确定你的python目录在哪里。它通常在C:\Python27. 如果您的不同,请从以下命令更改它。

If after you install it python still isn't recognized, then in PowerShell enter this:

如果安装后仍然无法识别 python,则在 PowerShell 中输入:

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

[环境]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

Close PowerShell and then start it again to make sure Python now runs. If it doesn't, restart may be required.

关闭 PowerShell,然后再次启动它以确保 Python 现在可以运行。如果没有,则可能需要重新启动。

enter image description here

在此处输入图片说明

回答by Akhilesh

I have found the answer... click on the installer and check the box "Add python to environment variables" DO NOT uninstall the old one rather click on modify....Click on link for picture...

我找到了答案......点击安装程序并选中“将python添加到环境变量”框不要卸载旧的而是点击修改......点击图片链接......

enter image description here

在此处输入图片说明

回答by Ke Du

I have met same issue when I install Python, and it is resolved when I set a PATH in system, here are the steps.

我在安装 Python 时遇到了同样的问题,当我在系统中设置 PATH 时解决了这个问题,以下是步骤。

  • Navigate to "Control Panel" -> "System"
  • Click "Advanced system settings" on the left
  • Click "Environment Variables"
  • Search and click "Path" variable
  • Click "Edit"
  • Add "C:\"to the environment variables field, if you are using Windows7, then separate it by a semicolon from the existing entry. If you are using Windows10, just simply click "New" to add.
  • Reopen the Command Prompt and try enter image description here
  • 导航到“控制面板”->“系统”
  • 点击左侧的“高级系统设置”
  • 点击“环境变量”
  • 搜索并单击“路径”变量
  • 点击“编辑”
  • 将“C:\”添加到环境变量字段,如果您使用的是 Windows7,则用分号将其与现有条目分开。如果您使用的是 Windows10,只需单击“新建”即可添加。
  • 重新打开命令提示符并尝试 在此处输入图像描述

回答by Kevin

Another helpful but simple solution might be restarting your computer after doing the download if Python is in the PATH variable. This has been a mistake I usually make when downloading Python onto a new machine.

如果 Python 在 PATH 变量中,另一个有用但简单的解决方案可能是在下载后重新启动计算机。这是我在将 Python 下载到新机器上时经常犯的错误。

回答by SashJK

Type py -v instead of python -v in command prompt

在命令提示符中键入 py -v 而不是 python -v

回答by Black Mamba

Open CMD with administrative access(Right click then run as administrator) then type the following command there:

使用管理权限打开 CMD(右键单击然后以管理员身份运行),然后在那里输入以下命令:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

Replace My_python_lib with the folder name of your installed python like for me it was C:\python27. Then to check if the path variable is set, type echo %PATH%you'll see your python part in the end. Hence now pythonis accessible. From this tutorial

将 My_python_lib 替换为您安装的 python 的文件夹名称,就像对我来说是C:\python27. 然后检查是否设置了路径变量,输入echo %PATH%你会在最后看到你的 python 部分。因此现在python可以访问。 从本教程

回答by Karim Mokhtar Mohamed

i solved this by running CMD in administration mode, so try this.

我通过在管理模式下运行 CMD 解决了这个问题,所以试试这个。