关于python:ImportError:没有名为pip的模块

ImportError: No module named pip

操作系统:Mac OS X 10.7.5python版本:2.7.5

我已经从https://pypi.python.org/pypi/setuptools安装了setuptools 1.0和ez_setup.py。然后我从https://pypi.python.org/pypi/pip/1.4.1下载pip.1.4.1包。

在iterm中运行"[sudo]python setup.py install"显示

running install
running bdist_egg running egg_info writing requirements to
pip.egg-info/requires.txt writing pip.egg-info/PKG-INFO writing
top-level names to pip.egg-info/top_level.txt writing dependency_links
to pip.egg-info/dependency_links.txt writing entry points to
pip.egg-info/entry_points.txt warning: manifest_maker: standard file
'setup.py' not found

reading manifest file 'pip.egg-info/SOURCES.txt' writing manifest file
'pip.egg-info/SOURCES.txt' installing library code to
build/bdist.macosx-10.6-intel/egg running install_lib warning:
install_lib: 'build/lib' does not exist -- no Python modules to
install

creating build/bdist.macosx-10.6-intel/egg creating
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/PKG-INFO -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pip.egg-info/SOURCES.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/dependency_links.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/entry_points.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/not-zip-safe ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/requires.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/top_level.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO creating
'dist/pip-1.4.1-py2.7.egg' and adding
'build/bdist.macosx-10.6-intel/egg' to it removing
'build/bdist.macosx-10.6-intel/egg' (and everything under it)
Processing pip-1.4.1-py2.7.egg removing
'/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg'
(and everything under it) creating
/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg
Extracting pip-1.4.1-py2.7.egg to
/Users/dl/Library/Python/2.7/lib/python/site-packages pip 1.4.1 is
already the active version in easy-install.pth Installing pip script
to /Users/dl/Library/Python/2.7/bin Installing pip-2.7 script to
/Users/dl/Library/Python/2.7/bin

Installed
/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg
Processing dependencies for pip==1.4.1 Finished processing
dependencies for pip==1.4.1

然后我输入了"pip install",错误消息显示如下

Traceback (most recent call last): File
"/Library/Frameworks/Python.framework/Versions/2.7/bin/pip", line 9,
in
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')() File"build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 357, in
load_entry_point File
"build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 2394, in
load_entry_point File
"build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 2108, in
load ImportError: No module named pip

以前遇到过同样问题的人能给我一些提示来解决吗?


我也有同样的问题。我的解决方案:

对于Python 3

1
sudo apt-get install python3-pip

对于Python 2

1
sudo apt-get install python-pip


在Mac上使用BREW是更好的选择,因为apt get不可用。命令:

如果机器上同时安装了python2和python3

1
python2.7 -m ensurepip --default-pip

只需解决这个问题。

如果您在python3中缺少pip,那么只需在上面的命令中将python2.7更改为python3


安装ez_安装程序后,您应该可以使用easy_install。要安装pip只需执行以下操作:

1
easy_install pip


我认为以上这些答案都不能解决你的问题。

我也曾经对这个问题感到困惑。您应该按照官方指南pip安装(目前涉及运行单个get-pip.pypython脚本)手动安装pip

在那之后,只有sudo pip install Django。错误将消失。


当我试图安装nova客户机时,遇到了同样的问题。

1
2
3
4
spencers-macbook-pro:python-novaclient root# python  setup.py install    
running install
/usr/bin/python: No module named pip
error: /usr/bin/python -m pip.__init__ install   'pbr>=0.5.21,<1.0' 'iso8601>=0.1.4' 'PrettyTable>=0.6,<0.8' 'requests>=1.1' 'simplejson>=2.0.9' 'six' 'Babel>=0.9.6' returned 1

我使用自制啤酒,因此我与sudo easy_install pip解决了这个问题。

1
2
3
4
5
6
7
8
9
spencers-macbook-pro:python-novaclient root# brew search pip
aespipe     brew-pip    lesspipe    pipebench   pipemeter   spiped  pipeviewer

If you meant"pip" precisely:

Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
    sudo easy_install pip
spencers-macbook-pro:python-novaclient root# sudo easy_install pip

如果使用MacPorts,命令应该类似。


我知道这个线程是旧的,但是我在OSX上为自己解决了这个问题,与这里描述的不同。

基本上,我通过BREW重新安装了python2.7,它附带了pip。

安装xcode(如果尚未安装):

1
xcode-select –install

按以下说明安装BREW:

1
ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

然后通过BREW安装python:

1
brew install python

你完成了。在我的情况下,我只需要安装pyserial。

1
pip install pyserial


尝试通过python安装pip

请转到:https://pip.pypa.io/en/stable/installing/

下载get-pip.py,然后运行:

1
(sudo) python get-pip.py

我从这里下载了pip二进制文件,它解决了这个问题。


我的PY版本是3.7.3,这个命令有效

python3.7 -m pip install requests

请求库-用于从Web API检索数据。

这将运行pip模块,并要求它在pypi.org(python包索引)上找到请求库,并将其安装到本地系统中,以便您可以导入它。


我通过将pythonpath设置为站点包位置,解决了Linux上的类似错误。这是在运行python get-pip.py --prefix /home/chet/pip之后。

1
2
3
4
5
6
7
8
9
10
[chet@rhel1 ~]$ ~/pip/bin/pip -V
Traceback (most recent call last):
  File"/home/chet/pip/bin/pip", line 7, in <module>
    from pip import main
ImportError: No module named pip

[chet@rhel1 ~]$ export PYTHONPATH=/home/chet/pip/lib/python2.6/site-packages

[chet@rhel1 ~]$ ~/pip/bin/pip -V
pip 9.0.1 from /home/chet/pip/lib/python2.6/site-packages (python 2.6)

在终端中尝试此操作:

1
ls -lA /usr/local/bin | grep pip

在我的例子中,我得到:

1
2
3
4
-rwxr-xr-x 1 root  root      284 Сен 13 16:20 pip
-rwxr-xr-x 1 root  root      204 Окт 27 16:37 pip2
-rwxr-xr-x 1 root  root      204 Окт 27 16:37 pip2.7
-rwxr-xr-x 1 root  root      292 Сен 13 16:20 pip-3.4

所以在我的例子中,pip2 pip2.7有效,而pip