Python 导入错误:没有名为 pip 的模块

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

ImportError: No module named pip

pythonpip

提问by David Lu

OS: Mac OS X 10.7.5 Python Ver: 2.7.5

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

I have installed setuptools 1.0 with ez_setup.py from https://pypi.python.org/pypi/setuptoolsThen I download pip.1.4.1 pkg from https://pypi.python.org/pypi/pip/1.4.1.

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

Run (sudo) python setup.py installin iTerm shows that

python setup.py install在 iTerm 中运行 (sudo)显示

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

Then I inputed pip install, the error message showed like that

然后我输入pip install,错误信息是这样显示的

Traceback (most recent call last):   File
"/Library/Frameworks/Python.framework/Versions/2.7/bin/pip", line 9,
in <module>
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

Anyone who met the same problem before and can give me some tips to solve it?

任何人以前遇到过同样的问题,可以给我一些解决方法的提示吗?

回答by spuder

I ran into this same issue when I attempted to install the nova client.

我在尝试安装 nova 客户端时遇到了同样的问题。

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

I use homebrew so I worked around the issue with sudo easy_install pip

我使用自制软件,所以我解决了这个问题 sudo easy_install pip

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

The commands should be similar if you use macports.

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

回答by MadeOfAir

I downloaded pipbinaries from hereand it resolved the issue.

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

回答by Artem Zinoviev

In terminal try this:

在终端试试这个:

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

in my case i get:

就我而言,我得到:

-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

So pip2 || pip2.7 in my case works, and pip

所以 pip2 || pip2.7 在我的情况下工作,和 pip

回答by Manuel Riel

After installing ez_setup, you should have easy_installavailable. To install pipjust do:

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

easy_install pip

回答by sudoz

I think none of these answers above can fix your problem.

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

I was also confused by this problem once. You should manually install pipfollowing the official guide pip installation(which currently involves running a single get-pip.pyPython script)

我也有一次被这个问题搞糊涂了。您应该pip按照官方指南pip 安装手动安装(目前涉及运行单个get-pip.pyPython 脚本

after that, just sudo pip install Django. The error will be gone.

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

回答by sudoz

I had the same problem. My solution:

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

For Python 3

对于 Python 3

sudo apt-get install python3-pip

For Python 2

对于 Python 2

sudo apt-get install python-pip

回答by ScottyC

I know this thread is old, but I just solved the problem for myself on OS X differently than described here.

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

Basically I reinstalled Python 2.7 through brew, and it comes with pip.

基本上我通过 brew 重新安装了 Python 2.7,它带有 pip。

Install Xcode if not already:

如果还没有安装 Xcode:

xcode-select –install

Install Brew as described here:

按照此处所述安装 Brew :

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

Then install Python through Brew:

然后通过 Brew 安装 Python:

brew install python

And you're done. In my case I just needed to install pyserial.

你已经完成了。就我而言,我只需要安装 pyserial。

pip install pyserial

回答by iosCurator

On Mac using brewis a better option as apt-getis not available. Command:

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

In case you have both python2 & python3 installed on machine

如果您在机器上安装了 python2 和 python3

python2.7 -m ensurepip --default-pip

simply should solve the issue.

应该可以解决问题。

If instead you are missing pip from python 3 then simply change python2.7to python3in the command above.

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

回答by GargantuChet

I solved a similar error on Linux by setting PYTHONPATH to the site-packages location. This was after running python get-pip.py --prefix /home/chet/pip.

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

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

回答by Qiangzini

Try to install pipthrough Python:

尝试pip通过 Python安装:

Please go to: https://pip.pypa.io/en/stable/installing/

请前往:https: //pip.pypa.io/en/stable/installing/

and download get-pip.py, and then run:

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

(sudo) python get-pip.py