python 2.7:无法在 Windows 上 pip “bash: pip: command not found”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25328818/
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
python 2.7: cannot pip on windows "bash: pip: command not found"
提问by Saladsamurai
I am trying to install the SciPy stack located at https://scipy.org/stackspec.html[I am only allowed 2 links; trying to use them wisely]. I realize that there are much easier ways to do this, but I think there is a lot to be learned by doing it manually. I am relatively new to a lot of this stuff, so I apologize if I sound ignorant at any point.
我正在尝试安装位于https://scipy.org/stackspec.html[我只允许 2 个链接;试图明智地使用它们]。我意识到有更简单的方法可以做到这一点,但我认为通过手动操作可以学到很多东西。我对很多这些东西都比较陌生,所以如果我在任何时候听起来无知,我深表歉意。
I am running Windows 7 Enterprise - 64 bit. Here is what I have done so far:
我在跑步 Windows 7 Enterprise - 64 bit。这是我到目前为止所做的:
Installed
python-2.7.8.msi (32-bit)from https://www.python.org/download/releases/2.7.8/Installed
numpy-1.8.1-win32-superpack-python2.7from http://sourceforge.net/projects/numpy/files/
Test:import numpy as np---> no errorsInstalled
scipylibrary,scipy-0.14.0-win32-superpack-python2.7.exefrom (SCIPY DOT ORG LINK REMOVED) Test:import scipy as sp---> no errorsInstalled
matplotlib:matplotlib-1.3.1.win32-py2.7.exefrom (MATPLOTLIB DOT ORG LINK REMOVED)Installed
PIPby running script here: https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.pyI just copied-pasted script to a new file inIDLE,
saved asC:\Python27\Scripts\pip_install.pyand clickedRun>module. No errors reported.
python-2.7.8.msi (32-bit)从https://www.python.org/download/releases/2.7.8/安装numpy-1.8.1-win32-superpack-python2.7从 http://sourceforge.net/projects/numpy/files/安装
测试:import numpy as np---> 没有错误已安装的
scipy库,scipy-0.14.0-win32-superpack-python2.7.exe来自 (SCIPY DOT ORG LINK REMOVED) 测试:import scipy as sp---> 没有错误安装
matplotlib:matplotlib-1.3.1.win32-py2.7.exe来自(MATPLOTLIB DOT ORG LINK REMOVED)PIP通过在此处运行脚本安装:https: //raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py我只是将脚本复制粘贴到 中的新文件IDLE,
另存为C:\Python27\Scripts\pip_install.py并单击Run>module。没有错误报告。
Does the path on which I saved
pip_install.pymatter?
我保存的路径
pip_install.py重要吗?
6. HERE IS WHERE I FAIL
6. 这 就是我失败的地方
Attempted to install matlibplot dependency dateutil: Opened a Cygwin Shell, and typed
尝试安装 matlibplot 依赖项 dateutil: Opened a Cygwin Shell, and typed
cd C:\Python27 ! is it necessary to cd to python directtory?
pip install python-dateutil
This results in the error:
这导致错误:
bash: pip: command not found
I get the same error attempting from cmd.
尝试从cmd.
Any help is appreciated; the closest I found was bash: pip: command not found. But the OSX nature of it is just enough to confise me further.
任何帮助表示赞赏;我发现的最接近的是bash: pip: command not found。但它的 OSX 特性足以让我进一步了解。
UPADTE:
更新:
I added the pip-path per Paul H's suggestion below. It made the error go away, but strangely, nothing I pipactually installs. For example, in Cygwin, I type:
我根据下面 Paul H 的建议添加了 pip-path。它使错误消失了,但奇怪的是,我pip实际上没有安装任何东西。例如,在 中Cygwin,我输入:
cbennett2> pip install python-dateutil
cbennett2>
You can see that there is no output or feedback from the shell (which I think there should be). Then when I go to a new python shell:
您可以看到 shell 没有输出或反馈(我认为应该有)。然后当我去一个新的 python shell 时:
>>> from dateutil.parser import parse
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
from dateutil.parser import parse
ImportError: No module named dateutil.parser
>>>>
This happens with all of the modules that I thought I had pip'd ... pandas, tornado, etc.
这发生在我认为我已经 pip'd 的所有模块中......熊猫,龙卷风等。
采纳答案by Paul H
On Windows, piplives in C:\[pythondir]\scripts.
在 Windows 上,pip位于C:\[pythondir]\scripts.
So you'll need to add that to your system path in order to run it from the command prompt. You could alternatively cdinto that directory each time, but that's a hassle.
因此,您需要将其添加到系统路径中,以便从命令提示符运行它。您也可以cd每次都进入该目录,但这很麻烦。
See the top answer here for info on how to do that: Adding Python Path on Windows 7
有关如何执行此操作的信息,请参阅此处的最佳答案: 在 Windows 7 上添加 Python 路径
Also, that is a terrifying way to install pip. Grab it from Christophe Gohlke. Grab everything else from there for that matter.
http://www.lfd.uci.edu/~gohlke/pythonlibs/
此外,这是一种可怕的安装方式pip。从 Christophe Gohlke 那里获取它。从那里抓住其他一切。
http://www.lfd.uci.edu/~gohlke/pythonlibs/
回答by user2954167
I had a similar problem running SciPy on my computer. There are two ways to fix this problem: 1. Yes you do need to cd into your python directory. 2. Sometimes you have to tell the computer explicitly what path to go through, you have to find the program you're using, open up the properties, and reroute the path it takes to run. 3. consult the manual: http://matplotlib.org/users/installing.htmlor http://www.scipy.org/install.html
我在我的计算机上运行 SciPy 时遇到了类似的问题。有两种方法可以解决此问题: 1. 是的,您确实需要 cd 进入您的 python 目录。2. 有时你必须明确告诉计算机要经过的路径,你必须找到你正在使用的程序,打开属性,并重新路由它运行所需要的路径。3.查阅手册:http: //matplotlib.org/users/installing.html或http://www.scipy.org/install.html
the Scipy package is very finicky, and needs things spelled out in obnoxious detail.
Scipy 包非常挑剔,需要详细说明令人讨厌的细节。
回答by Ivan Temchenko
- press
[win] + Pause - Advanced settings
- System variables
- Append
;C:\python27\Scriptsto the end ofPathvariable - Restart console
- 按
[win] + Pause - 高级设置
- 系统变量
- 附加
;C:\python27\Scripts到Path变量的末尾 - 重启控制台
回答by ella2469
I found this much simpler. Simply type this into the terminal:
我发现这要简单得多。只需在终端中输入:
PATH=$PATH:C:\[pythondir]\scripts
回答by Dat TT
On windows 7, you have to use this command: python -m pip install xxx. All above don't work for me.
在 Windows 7 上,你必须使用这个命令:python -m pip install xxx。以上都对我不起作用。
回答by Buzz
As long as pip lives within the scripts folder you can run
只要 pip 位于脚本文件夹中,您就可以运行
python -m pip ....
python -m pip ....
This will tell python to get pip from inside the scripts folder. This is also a good way to have both python2.7 and pyhton3.5 on you computer and have them in different locations. I currently have both python2 and pyhton3 installed on windows. When I type pythonit defaults to python2. But if I type python3I can use python3. (I also had to change the python.exe file for python3 to "python3.exe")If I need to install flask for python 2 I can run
这将告诉 python 从脚本文件夹中获取 pip。这也是在您的计算机上同时安装 python2.7 和 pyhton3.5 并将它们放在不同位置的好方法。我目前在 Windows 上安装了 python2 和 pyhton3。当我输入时,python它默认为 python2。但是如果我输入python3我可以使用python3。(我还必须将 python3 的 python.exe 文件更改为“python3.exe”)如果我需要为 python 2 安装烧瓶,我可以运行
python -m pip install flask
python -m pip install flask
and it will be installed in the pyhton2 folder, but if I need flask for python 3 I run:
它将安装在 pyhton2 文件夹中,但如果我需要 python 3 的烧瓶,我运行:
python3 -m pip install flask
python3 -m pip install flask
and I now have it in the python3 folder
我现在把它放在 python3 文件夹中
回答by FearlessFuture
If this is for Cygwin, it installs "pip" as "pip2". Just create a softlink to "pip2" in the same location where "pip2" is installed.
如果这是用于 Cygwin,它会将“pip”安装为“pip2”。只需在安装“pip2”的同一位置创建一个指向“pip2”的软链接。
回答by blueboy21
The problem is that your Python version and the library you want to use are not same versionally (Python). Even if you install Python's latest version, your PATH might not change properly and automatically. Thus, you should change it manually.After matching their version, it will work.
问题是您的 Python 版本和您要使用的库在版本上不同(Python)。即使您安装了 Python 的最新版本,您的 PATH 也可能不会自动正确更改。因此,您应该手动更改它。匹配他们的版本后,它将起作用。
Ex: When I tried to install Django3, I got same error. I noticed that my PATH still seems C:\python27\Scripts though I already install Python3.8, so that I manually edited my PATH C:\python38\Scripts and reinstalled pip install Django and everything worked well.
例如:当我尝试安装 Django3 时,我遇到了同样的错误。我注意到虽然我已经安装了 Python3.8,但我的 PATH 看起来仍然是 C:\python27\Scripts,所以我手动编辑了我的 PATH C:\python38\Scripts 并重新安装了 pip install Django 并且一切正常。

