‘pip’不被识别为内部或外部命令

问题:’pip’不被识别为内部或外部命令

尝试在计算机上安装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

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

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%

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

回答 0

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

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

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

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

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

感谢Scott Bartell指出这一点。

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.

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

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

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 instance after entering the above command in order to utilize the new environment variable.

Thanks to Scott Bartell for pointing this out.


回答 1

对于Windows,在安装软件包时,键入:

python -m pip install [packagename]

For windows when you install a package you type:

python -m pip install [packagename]

回答 2

对我而言:

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

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

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

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).

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


回答 3

到目前为止,在3.7.3版中,获取正确的系统变量存在一点问题。

尝试这个:

  1. 在cmd中输入“ start%appdata%”。

  2. 之后,该文件浏览器应在“ ../AppData/Roaming”中弹出。

返回一个目录,然后导航到“本地/程序/ Python / Python37-32 /脚本”。

注意:版本号可能会有所不同,因此,如果您复制并粘贴上述文件路径,它将无法正常工作。

完成此操作后,您现在具有已下载Python的正确位置。通过在地址栏中选择整个目录来复制文件路径。

完成此操作后,单击开始图标,然后导航到“控制面板”>“系统和安全性”>“系统”。然后单击面板左侧的“高级系统设置”。

单击右下角的环境变量后,将有两个框,一个上框和一个下框。在上方的框中:单击“路径”变量,然后单击右侧的“编辑”。单击“新建”,然后粘贴目录路径。它看起来应该像这样:

单击确定三次,打开cmd的新窗口,然后键入:pip。看看是否可行。

祝好运!

As of now, version 3.7.3 I had a little bit of an issue with getting the right system variable.

Try this:

  1. Type ‘start %appdata%’ in cmd.

  2. After that file explorer should pop up in ‘../AppData/Roaming’.

Go back one directory and navigate to ‘Local/Programs/Python/Python37-32/Scripts’.

NOTE: The version number may be different so if you copy and paste the above file path it could not work.

After you do this you now have the correct location of your downloaded Python. Copy your file path by selecting the whole directory in the address bar.

Once you do that click the start icon and navigate to the Control Panel > System and Security > System. Then click “Advanced System Settings” on the left side of the panel.

Once there click environment Variables on the bottom right and there will be two boxes, an upper and a lower box. In the upper box: Click on the ‘Path’ Variable and click ‘edit’ located on the right. Click ‘New’ and paste your directory Path. It should look something like this:

Click Ok three times, open a NEW window of cmd and type: pip. See if it works.

Good Luck!


回答 4

替代方式。

如果您不想添加PATH(如先前的书面回答所指出的那样),

但是您想执行pip作为命令,则可以使用py -m前缀做。

鉴于您必须一次又一次地执行此操作。

例如。

py -m <command>

py -m pip install --upgrade pip setuptools

另外,还要确保有pippy安装

Alternate way.

If you don’t want to add the PATH as the previous well written answers pointed out,

but you want to execute pip as your command then you can do that with py -m as prefix.

Given that you have to do it again and again.

eg.

py -m <command>

as in

py -m pip install --upgrade pip setuptools

Also make sure to have pip and py installed


回答 5

同样,长方法-在尝试了上述所有项目之后,这是最后的选择:

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

cd在车轮所在目录中之后

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


回答 6

根据Python 3.6文档

默认情况下,可能未安装pip。一种可能的解决方法是:

python -m ensurepip --default-pip

As per Python 3.6 Documentation

It is possible that pip does not get installed by default. One potential fix is:

python -m ensurepip --default-pip

回答 7

转到控制面板>>卸载 更改程序,然后双击Python XXX修改安装。确保已检查并安装了PIP组件。

Go to control Panel >> Uninstall or change Program and double click on Python XXX to modify install. Make sure PIP component is checked and install.


回答 8

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

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 pip to run. All it took was running pip.exe install -package- instead of pip install -package-. Just a thought.


回答 9

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

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


回答 10

控制面板->添加/删除程序-> Python->修改->可选功能(您可以单击所有内容),然后按下一步->选中“将python添加到环境变量”->安装

这应该可以解决您的路径问题,因此请跳至命令提示符,您现在可以使用pip。

Control Panel -> add/remove programs -> Python -> Modify -> optional Features (you can click everything) then press next -> Check “Add python to environment variables” -> Install

And that should solve your path issues, so jump to command prompt and you can use pip now.


回答 11

尝试进入Windows powershell或cmd提示符并输入:

python -m pip install openpyxl

Try going to windows powershell or cmd prompt and typing:

python -m pip install openpyxl


回答 12

在最新版本的python 3.6.2及更高版本中,提供了

C:\ Program Files(x86)\ Python36-32 \ Scripts

您可以将路径添加到我们的环境变量路径,如下所示

设置路径后,请确保关闭命令提示符或git。还应该在管理员模式下打开命令提示符。这是Windows 10的示例。

In latest version python 3.6.2 and above, is available in

C:\Program Files (x86)\Python36-32\Scripts

You can add the path to our environment variable path as below

Make sure you close your command prompt or git after setting up your path. Also should you open your command prompt in administrator mode. This is example for windows 10.


回答 13

甚至我都不熟悉,但是C:\ Python34 \ Scripts> pip install django为我工作。路径应设置为Python安装的Script文件夹所在的位置,即C:\ Python34 \ Scripts。我想这是因为django是一个基于python的框架,这就是为什么在安装时必须维护此目录结构的原因。

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.


回答 14

您可以尝试pip3,例如:

C:> pip3 install pandas

Yo can try pip3, something like:

C:> pip3 install pandas

回答 15

我刚刚安装了python 3.6.2。

我知道了

C:\ Users \ USERNAME \ AppData \ Local \ Programs \ Python \ Python36-32 \ Scripts

I have just installed python 3.6.2.

I got the path as

C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\Scripts


回答 16

在Windows中,打开cmd并使用来找到PYTHON_HOME的位置where python,现在使用以下命令将该位置 添加到您的环境PATH中:

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

参考此


在Linux中,打开终端并使用来找到PYTHON_HOME的位置which python,现在使用来将其添加PYTHON_HOME/Scripts到PATH变量中:

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

In Windows, open cmd and find the location of PYTHON_HOME using where python, now add this location to your Environment PATH using:

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

or Refer this


In Linux, open terminal and find the location of PYTHON_HOME using which python, now add the PYTHON_HOME/Scripts to the PATH variable using:

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

回答 17

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

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

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.

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

回答 18

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

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

Or If you are using PyCharm (2017.3.3) like me, just change directory in terminal and install:

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

回答 19

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

path =%path%; D:\ Program Files \ python3.6.4 \ Scripts; (新路径=当前路径; python脚本文件夹的路径)

In windows environment, just execute below commands in dos shell.

path=%path%;D:\Program Files\python3.6.4\Scripts; (new path=current path;path of the python script folder)


回答 20

我遇到了同样的问题以管理员身份运行Windows PowerShell 可以解决我的问题。

I was facing same issue Run Windows PowerShell as Administrator it resolved my issue.


回答 21

最常见的是:

cmd.exe

python -m pip install --user [name of your module here without brackets]

Most frequently it is:

in cmd.exe write

python -m pip install --user [name of your module here without brackets]

回答 22

更正PATH之后,我仍然收到此错误。

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

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

I continued to recieve this error after correcting my 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.

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


回答 23

我有同样的问题。你只需要去你的

C:\ Python27 \脚本

并将其添加到环境变量中。设置路径后,只需在C:\ Python27 \ Scripts上运行pip.exe文件,然后在cmd中尝试pip。但是,如果没有任何反应,请尝试运行所有pip应用程序,例如pip2.7和pip2.exe。点子将像魅力一样工作。

I had this same issue. You just need to go to your

C:\Python27\Scripts

and add it to environment variables. After path setting just run pip.exe file on C:\Python27\Scripts and then try pip in cmd. But if nothing happens try running all pip applications like pip2.7 and pip2.exe. And pip will work like a charm.


回答 24

解决此问题的一种非常简单的方法是在文件资源管理器中打开安装pip的路径,然后单击该路径,然后键入cmd,这将设置路径,使您的安装方式更容易。

迟到了4年,但几天前我遇到了同样的问题,其他所有方法对我都不起作用。

A very simple way to get around this is to open the path where pip is installed in file explorer, and click on the path, then type cmd, this sets the path, allowing you to install way easier.

4 years late, but I ran into the same issue a couple days ago and all the other methods didn’t work for me.


回答 25

尝试卸载Python,删除其余程序文件,然后重新全新安装。它为我工作。当我迁移到新笔记本电脑并使用迁移软件将软件从旧笔记本电脑迁移到新笔记本电脑时,发生了此错误。是的,效果不是很好。

Try uninstall Python, delete the remaining program files, then install it again fresh. It worked for me. This error happened to me when I migrate to a new laptop and used a migration software to move my software from the old laptop to the new one. And yeah, didn’t work quite well.


回答 26

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

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

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

Small clarification: in “Windows 7 64 bit PC”, after adding ...Python34\Scripts to the path variable, pip install pygame didn’t work for me.

So I checked the “…Python34\Scripts” folder, it didn’t have pip, but it had pip3 and pip3.4. So I ran pip3.4 install pygame .... .whl. It worked.

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


回答 27

对我来说,问题是,在PATH中添加以下内容后,系统未重新启动。

C:\Users\admin\AppData\Local\Programs\Python\Python37\Scripts

For me the issue was, system was not RESTARTED after adding below in PATH.

C:\Users\admin\AppData\Local\Programs\Python\Python37\Scripts


回答 28

安装SQL 2019 Python时,PIP存在一些已知问题,需要修复(步骤7) https://docs.microsoft.com/zh-cn/sql/advanced-analytics/known-issues-for-sql-server-机器学习服务?view = sql-server-ver15

pip配置了需要TLS / SSL的位置,但是Python中的ssl模块不可用。

Workaround
Copy the following files:

libssl-1_1-x64.dll
libcrypto-1_1-x64.dll

from the folder 
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\Library\bin
to the folder 
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\DLLs

Then open a new DOS command shell prompt.

When installing SQL 2019 Python, there are known issues for PIP which require a fix (step 7) https://docs.microsoft.com/en-us/sql/advanced-analytics/known-issues-for-sql-server-machine-learning-services?view=sql-server-ver15

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Workaround
Copy the following files:

libssl-1_1-x64.dll
libcrypto-1_1-x64.dll

from the folder 
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\Library\bin
to the folder 
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\DLLs

Then open a new DOS command shell prompt.

回答 29

对于Mac,在终端中运行以下命令

echo  export "PATH=$HOME/Library/Python/2.7/bin:$PATH"

For mac run below command in terminal

echo  export "PATH=$HOME/Library/Python/2.7/bin:$PATH"