我在电脑上安装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

当前回答

如果你正在使用Python,例如PyCharm,你应该像这样将库安装到Python库路径:

pip install --target=C:\Users\<...>\lib <Library-Name>

真正的如。

pip install --target=C:\Users\devel\AppData\Local\Programs\Python\Python36\Lib requests <br>

PS:如果你想检查是否安装,

<Library-Name> --version

不能正常工作。

其他回答

在Windows环境中,只需在DOS shell中执行以下命令。

路径= % %路径;D: \ \ python3.6.4 \脚本程序文件; (new path=当前路径;Python脚本文件夹的路径)

替代方法。

如果你不想像前面写得很好的答案所指出的那样添加PATH,

但是你想要执行PIP作为你的命令,那么你可以用py -m作为前缀。

考虑到你要一次又一次地做这件事。

eg.

py -m <command>

就像在

py -m pip install --upgrade pip setuptools

还要确保安装了pip和py

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

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

我认为Python 2.7.9及更高版本已经预安装,它将在你的脚本文件夹中。

因此,您必须将“scripts”文件夹添加到路径中。我的安装在C:\Python27\Scripts中。检查你的路径,看看你的路径是什么,这样你就可以相应地改变下面的路径。然后转到PowerShell,在PowerShell中粘贴以下代码并按Enter键。在此之后,重新启动,您的问题将得到解决。

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

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