Python 'pip' 不被识别为内部或外部命令

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

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

pythondjangowindowspip

提问by user3597950

I'm running into a weird error when trying to install Django on my computer.

尝试在我的计算机上安装 Django 时遇到了一个奇怪的错误。

This is the sequence that I typed into my command line:

这是我在命令行中输入的序列:

C:\Python34>python get-pip.py
Requirement already up-to-date: pip in c:\python34\lib\site-packages
Cleaning up...

C:\Python34>pip install Django
'pip' is not recognized as an internal or external command,
operable program or batch file.

C:\Python34>lib\site-packages\pip install Django
'lib\site-packages\pip' is not recognized as an internal or external command,
operable program or batch file. 

What could be causing this?

什么可能导致这种情况?

EDIT _______________________

编辑 _______________________

As requested this is what I get when I type in echo %PATH%

根据要求,这是我输入 echo %PATH% 时得到的

C:\Python34>echo %PATH%
C:\Program Files\ImageMagick-6.8.8-Q16;C:\Program Files (x86)\Intel\iCLS Client\
;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\S
ystem32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\
Windows Live\Shared;C:\Program Files (x86)\Intel\OpenCL SDK.0\bin\x86;C:\Progr
am Files (x86)\Intel\OpenCL SDK.0\bin\x64;C:\Program Files\Intel\Intel(R) Mana
gement Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine C
omponents\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components
\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\P
rogram Files (x86)\nodejs\;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x
86)\git\cmd;C:\RailsInstaller\Ruby2.0.0\bin;C:\RailsInstaller\Git\cmd;C:\RailsIn
staller\Ruby1.9.3\bin;C:\Users\Javi\AppData\Roaming\npm

采纳答案by fr1tz

You need to add the path of your pip installation to your PATH system variable. By default, pip is installed to C:\Python34\Scripts\pip(pip now comes bundled with new versions of python), so the path "C:\Python34\Scripts" needs to be added to your PATH variable.

您需要将 pip 安装的路径添加到 PATH 系统变量中。默认情况下,pip 安装到C:\Python34\Scripts\pip(pip 现在与新版本的 python 捆绑在一起),因此需要将路径“C:\Python34\Scripts”添加到您的 PATH 变量中。

To check if it is already in your PATH variable, type echo %PATH%at the CMD prompt

要检查它是否已经在您的 PATH 变量中,请echo %PATH%在 CMD 提示符下键入

To add the path of your pip installation to your PATH variable, you can use the Control Panel or the setxcommand. For example:

要将 pip 安装路径添加到 PATH 变量,您可以使用控制面板或setx命令。例如:

setx PATH "%PATH%;C:\Python34\Scripts"


Note: According to the official documentation, "[v]ariables set with setx variables are available in future command windows only, not in the current command window". In particular, you will need to start a new cmd.exe instanceafter entering the above command in order to utilize the new environment variable.

注意:根据官方文档,“[v] 使用 setx 变量设置的变量仅在未来的命令窗口中可用,在当前的命令窗口中不可用”。特别是,您需要在输入上述命令后启动一个新的 cmd.exe 实例才能使用新的环境变量。

Thanks to Scott Bartell for pointing this out.

感谢 Scott Bartell 指出这一点。

回答by zygimantus

For me command:

对我来说命令:

set PATH=%PATH%;C:\Python34\Scripts

worked immediately (try after echo %PATH%and you will see that your path has the value C:\Python34\Scripts).

立即工作(在echo %PATH%之后尝试,您将看到您的路径值为 C:\Python34\Scripts)。

Thanks to: https://stackoverflow.com/a/9546345/1766166

感谢:https: //stackoverflow.com/a/9546345/1766166

回答by Sumit Nautiyal

Even I'm new to this but, C:\Python34\Scripts>pip install django ,worked for me. The path should be set as where the Script folder of Python installation is i.e.C:\Python34\Scripts. I suppose its because django is a framework which is based on python that's why this directory structure has to be maintained while installing.

即使我是新手,但 C:\Python34\Scripts>pip install django 对我有用。路径应设置为 Python 安装的 Script 文件夹所在的位置,即C:\Python34\Scripts。我想这是因为 django 是一个基于 python 的框架,这就是为什么在安装时必须维护这个目录结构的原因。

回答by poodytang

I think from Python 2.7.9 and higher pip comes pre installed and it will be in your scripts folder. So you have to add the "scripts" folder to the path. Mine is installed in C:\Python27\Scripts. Check yours to see what your path is so that you can alter the below accordingly, then Go to powershell, paste the below code in powershell and hit Enter key. After that, reboot and your issue will be resolved.

我认为从 Python 2.7.9 和更高版本开始,pip 已预先安装,它将位于您的脚本文件夹中。所以你必须将“scripts”文件夹添加到路径中。我的安装在 C:\Python27\Scripts 中。检查您的路径以查看您的路径,以便您可以相应地更改以下内容,然后转到 powershell,将以下代码粘贴到 powershell 中并按 Enter 键。之后,重新启动,您的问题将得到解决。

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

回答by Josh

I realize this is an old question, but I was having the same problem just now. After adding the proper folder (C:\Python33\Scripts) to the path, I still could not get pipto run. All it took was running pip.exe install -package-instead of pip install -package-. Just a thought.

我意识到这是一个老问题,但我刚才遇到了同样的问题。将正确的文件夹 ( C:\Python33\Scripts)添加到路径后,我仍然无法pip运行。所需要的只是运行 pip.exe install -package-而不是 pip install -package-. 只是一个想法。

回答by kosa

Small clarification: in "Windows 7 64 bit PC", after adding ...Python34\Scriptsto the path variable, pip install pygamedidn't work for me.

小说明:在“Windows 7 64 位 PC”中,添加...Python34\Scripts到路径变量后,pip install pygame对我不起作用。

So I checked the "...Python34\Scripts" folder, it didn't have pip, but it had pip3and pip3.4. So I ran pip3.4 install pygame .... .whl. It worked.

所以我检查了“...Python34\Scripts”文件夹,它没有pip,但它有pip3pip3.4。所以我跑了pip3.4 install pygame .... .whl。有效。

(Further open a command window in the same folder where you have the downloaded pygame...whlfile.)

(进一步在下载pygame...whl文件所在的文件夹中打开一个命令窗口。)

回答by sajad

set Path = %PATH%;C:\Python34\;C:\Python27\Scripts
Source

设置路径 =%PATH%;C:\Python34\;C:\Python27\Scripts

回答by Colin Miles

also, the long method - it was a last resort after trying all items above:

此外,长方法 - 在尝试上述所有项目后,这是最后的手段:

c:\python27\scripts\pip.exe install [package].whl

this after cd in directory where the wheel is located

这是在轮子所在目录中的 cd 之后

回答by natty

Try going to windows powershell or cmd prompt and typing:

尝试转到 windows powershell 或 cmd 提示符并键入:

python -m pip install openpyxl

python -m pip install openpyxl

回答by SensationSama

I continued to recieve this error after correcting my PATH.

更正我的 PATH 后,我继续收到此错误。

If your codebase requires that you have an earlier version of Python (2.7 in my case), it may have been a version prior to the existence of pip.

如果您的代码库要求您拥有较早版本的 Python(在我的情况下为 2.7),则它可能是存在 pip 之前的版本。

It's not very canonical but installing a more recent version worked for me. (I used 2.7.13)

它不是很规范,但安装更新的版本对我有用。(我用的是 2.7.13)