我在电脑上安装Django时遇到了一个奇怪的错误。

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

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.

是什么导致了这种情况?

这是当我输入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\2.0\bin\x86;C:\Progr
am Files (x86)\Intel\OpenCL SDK\2.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

当前回答

或者如果你像我一样使用PyCharm(2017-03-03),只需在终端中更改目录并安装:

cd C:\Users\{user}\PycharmProjects\test\venv\Scripts
pip install ..

其他回答

首先,检查pip版本,以及它在机器上的存在

 pip --version

or

 pip3 --version

如果没有安装pip,请安装它。

在Linux上,可以通过在终端上运行apt-get命令来安装pip3。

sudo apt-get -y install python3-pip

在Mac上,pip与Python分发包捆绑在一起,因此您需要重新安装Python

brew uninstall --ignore-dependencies python3 && brew install python3

在窗口上,当PATH文件中的pip不正确时,会发生此问题

您可以尝试下面的py前缀替代使其工作

python -m pip install [packagename]

设置pip PATH[详见Ani Menon Answer]

查找PYTHON_HOME的位置

where python

现在将这个位置添加到环境变量PATH使用

set PATH=%PATH%;<PYTHON_HOME>\Scripts

Or

在Linux上,打开一个终端并使用PYTHON_HOME找到它的位置

which python

现在使用以下方法将PYTHON_HOME/Scripts添加到PATH变量中:

PATH=$PATH:<PYTHON_HOME>\Scripts
export PATH

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

要检查它是否已经在你的PATH变量中,在CMD提示符处输入echo %PATH%

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

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

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

感谢Scott Bartell指出这一点。

我的命令是:

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

(在echo %PATH%之后尝试,你会看到你的路径值为C:\Python34\Scripts)。

Thanks to:在Windows环境变量PATH中添加一个目录

我也面临着同样的问题。以管理员身份运行Windows PowerShell。它解决了我的问题。

小说明:在“Windows 7 64位PC”中,添加后…Python34\脚本到路径变量,pip安装pygame不适合我。

所以我检查了“…Python34\Scripts"文件夹,它没有pip,但它有pip3和pip3.4。所以我运行pip3.4 install pygame .... .whl。它工作。

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