Python 我不能使用 pip (Windows)

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

I can't use pip (Windows)

pythonpipcommand-prompt

提问by Jason Procka

I'm wanting to learn machine learning, but it requires that I use 'pip.' I'm still very new to a lot of this stuff. I've installed Python 3.4 64-bit and get-py.py.

我想学习机器学习,但它要求我使用“pip”。我对很多这些东西还是很陌生。我已经安装了 Python 3.4 64 位和 get-py.py。

When I run pip install sklearnI get 'pip' is not recognized as an internal or external command, operable program or batch file.

当我跑步时,pip install sklearn我得到'pip' is not recognized as an internal or external command, operable program or batch file.

Here's a screenshot of my environmental variable PATH

这是我的环境变量 PATH 的屏幕截图

https://gyazo.com/c7ec926401878845d5c4f9a556cf00ee

https://gyazo.com/c7ec926401878845d5c4f9a556cf00ee

Any help would be greatly appreciated. I have checked out other posts where people had similar issues, but I tried various things and nothing worked.

任何帮助将不胜感激。我查看了其他人遇到类似问题的帖子,但我尝试了各种方法,但没有任何效果。

回答by Joe Samanek

Easiest solution is to just download a platform like Anaconda for example. It is Python with many libraries (sklearn, pandas, numpy, ...) and also with pip, all in a user-friendly Windows installer package, that takes care of everything for you.

最简单的解决方案是下载一个像 Anaconda 这样的平台。它是带有许多库(sklearn、pandas、numpy ……)和 pip 的 Python,所有这些都在一个用户友好的 Windows 安装程序包中,它会为您处理一切。

https://www.continuum.io/downloads

https://www.continuum.io/downloads

If you really want to do it yourself, then

如果你真的想自己做,那么

  1. download get-pip.py (https://bootstrap.pypa.io/get-pip.py)

  2. make sure you have Python installed and in your PATH, for example by running python --versionin command prompt

  3. Navigate to the directory, where you downloaded get-pip.py (in command prompt using the command cd).

  4. Run the command python get-pip.pyfrom a command prompt with admin privileges (possibly not needed, but just to make sure).

  5. This should be all. Close your command prompt, open it again and run pip --versionto test it. If it doesn't work, then search your computer for a file named pip.exe(most likely in your Python directory) and if you find it, add its path to your PATH variable (given the screenshot, I assume you know how to do this).

  1. 下载 get-pip.py ( https://bootstrap.pypa.io/get-pip.py)

  2. 确保你已经安装了 Python 并且在你的 PATH 中,例如通过python --version在命令提示符下运行

  3. 导航到下载 get-pip.py 的目录(在命令提示符中使用命令cd)。

  4. python get-pip.py从具有管理员权限的命令提示符运行命令(可能不需要,但只是为了确保)。

  5. 这应该是全部。关闭命令提示符,再次打开并运行pip --version以测试它。如果它不起作用,则在您的计算机中搜索一个名为pip.exe(最有可能在您的 Python 目录中)的文件,如果找到它,请将其路径添加到您的 PATH 变量中(根据屏幕截图,我假设您知道如何执行此操作) .

回答by AkshayKrish

I downloaded Python 3.6 and the pip was installed on my system. I found pip at below location:

我下载了 Python 3.6 并在我的系统上安装了 pip。我在以下位置找到了 pip:

C:\Users\Admin\AppData\Local\Programs\Python\Python36\Scripts

Also, before I found pip I used below command on my command prompt to install pyperclip:

另外,在我找到 pip 之前,我在命令提示符下使用了以下命令来安装 pyperclip:

python -m pip install pyperclip

回答by Odysseas

For anyone that might have installed Python using the MSI installer, and ticked the box to include pip, but still gets the error 'pip' is not recognized as an internal or external command, operable program or batch file:

对于可能已使用 MSI 安装程序安装 Python 并勾选包含的框的任何人pip,但仍然收到错误'pip' is not recognized as an internal or external command, operable program or batch file

It looks like that the pipexecutable is installed in the \Scriptssubdirectory of the Python installation, but that directory does not get automatically added to PATH.

看起来pip可执行文件安装在\ScriptsPython 安装的子目录中,但该目录不会自动添加到 PATH。

For me, since I had installed Python 2.7, the directory was C:\Python27\Scripts. After adding this path to the PATHenvironment variable, and open a new CMD window, pip was available as a command.

对我来说,因为我安装了 Python 2.7,所以目录是C:\Python27\Scripts. 将此路径添加到PATH环境变量后,并打开一个新的 CMD 窗口,pip 作为命令可用。

回答by Bosnian Coder

I've made a workaround that will help you, copy the batch script below and modify it as specified:

我已经制定了一个可以帮助您的解决方法,复制下面的批处理脚本并按照指定进行修改:

@"PATH to python.exe" "PATH to pip.exe" %*

For example like this:

例如像这样:

@"D:\dev\apps\python374\python.exe" "D:\dev\apps\python374\Scripts\pip.exe" %*

Save this file as pip.bat on Desktop and then move it to C:\Windows\system32.

在桌面上将此文件另存为 pip.bat,然后将其移动到 C:\Windows\system32。

enter image description here

在此处输入图片说明

回答by Joss Bird

If it is specifically pip you want you could install python again making sure to tick the install pip box which it sounds like you failed to upon initial installation.

如果它是您想要的特定 pip,您可以再次安装 python,确保勾选安装 pip 框,这听起来您在初始安装时失败了。

回答by Haara Marsch

I'm late now, but just add python to your environment variables.

我现在迟到了,但只需将 python 添加到您的环境变量中。

It′s explained in this short video, how to set up python to your environment variables: https://www.youtube.com/watch?v=Y2q_b4ugPWk

在这个短视频中解释了如何将python设置为您的环境变量:https: //www.youtube.com/watch?v=Y2q_b4ugPWk

after that ping should work on your cmd, without cd to C:\Users\Admin\AppData\Local\Programs\Python\Python36\Scripts

之后 ping 应该在你的 cmd 上工作,没有 cd 到 C:\Users\Admin\AppData\Local\Programs\Python\Python36\Scripts

回答by DaWiseguy

For Python 3.7 or higher at least (as today is October 4th 2019) in the installation window you need to check the box "add to PATH" when you first install Python.

至少对于 Python 3.7 或更高版本(今天是 2019 年 10 月 4 日),您需要在首次安装 Python 时选中“添加到 PATH”框。