简体   繁体   English

ImportError:没有名为 pip 的模块

[英]ImportError: No module named pip

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/setuptools Then I download pip.1.4.1 pkg from https://pypi.python.org/pypi/pip/1.4.1 . I have installed setuptools 1.0 with ez_setup.py from https://pypi.python.org/pypi/setuptools Then I download pip.1.4.1 pkg from https://pypi.python.org/pypi/pip/1.4.1 .

Run (sudo) python setup.py install in iTerm shows that在 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

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?以前遇到过同样问题的任何人都可以给我一些解决方法吗?

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

On Mac using brew is a better option as apt-get is not available.在 Mac 上使用brew是更好的选择,因为apt-get不可用。 Command:命令:

brew install python

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.7 to python3 in the command above.相反,如果您缺少 python 3 中的 pip,那么只需在上面的命令中将python2.7更改为python3

With macOS 10.15 and Homebrew 2.1.6 I was getting this error with Python 3.7.使用 macOS 10.15 和 Homebrew 2.1.6,我在使用 Python 3.7 时遇到此错误。 I just needed to run:我只需要运行:

python3 -m ensurepip

Now python3 -m pip works for me.现在python3 -m pip对我python3 -m pip

After installing ez_setup , you should have easy_install available.安装ez_setup 后,您应该可以使用easy_install To install pip just do:要安装pip只需执行以下操作:

easy_install pip

Try to install pip through Python:尝试通过 Python 安装pip

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

On some kind of Linux, like distros based on Debian, you might want to consider updating your ' apt-get ' first, in case you are installing python-pip through it.在某种 Linux 上,例如基于 Debian 的发行版,您可能需要考虑先更新“ apt-get ”,以防您通过它安装 python-pip。

sudo apt-get update

This might help apt-get to update its indexes and locate the python-pip package.这可能有助于 apt-get 更新其索引并找到 python-pip 包。 After this, u might install pip like this-在此之后,您可能会像这样安装 pip-

sudo apt-get install python-pip (Python2)
sudo apt-get install python3-pip (Python3)

Run跑步

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then run the following command in the folder where you downloaded: get-pip.py然后在您下载的文件夹中运行以下命令:get-pip.py

python get-pip.py

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,命令应该类似。

I think none of these answers above can fix your problem.我认为以上这些答案都不能解决您的问题。

I was also confused by this problem once.我也有一次被这个问题搞糊涂了。 You should manually install pip following the official guide pip installation (which currently involves running a single get-pip.py Python script )您应该按照官方指南pip 安装手动安装pip (目前涉及运行单个get-pip.py Python 脚本

after that, just sudo pip install Django .之后,只需sudo pip install Django The error will be gone.错误将消失。

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

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

I encountered the same error with Python 3.8.6 on MacOS Big Sur.我在 MacOS Big Sur 上使用 Python 3.8.6 遇到了同样的错误。

Whether I used pip or pip3 I'd get this error:无论我使用pip还是pip3我都会收到这个错误:

 File "/Users/marcelloromani/dev/<repository>/venv/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'

It turns out my virtualenv was out of date.原来我的 virtualenv 已经过时了。 This fixed the issue for me:这为我解决了问题:

  1. Remove the old virtualenv删除旧的 virtualenv
$ deactivate
$ rm -rf venv
  1. Initialise a new virtualenv初始化一个新的 virtualenv
$ virtualenv venv
$ . venv/bin/activate
  1. Install the new requirements then worked:安装新的要求然后工作:
$ pip install -r src/requirements.txt

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 || pip2.7 in my case works, and pip pip2.7 在我的情况下工作,和 pip

Download:下载:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then Install pip:然后安装pip:

py get-pip.py

Then Install biopython:然后安装biopython:

py -m pip install biopython

I wish it would be useful我希望它会有用

I encountered the issue ModuleNotFoundError: No module named 'pip' when I created a new Python 3 virtual environment using the command我在使用命令创建新的 Python 3 虚拟环境时遇到了问题ModuleNotFoundError: No module named 'pip'

python3 -m venv ~/venv/ontology    ## << note: "python3" (problematic)

which is a command often suggested (here, elsewhere).这是经常建议的命令(此处,其他地方)。 When I entered that venv, pip was nowhere to be found.当我进入那个 venv 时,找不到 pip。

In the interim, since first using that command to create Python virtual environments, my system Python had upgraded (Arch Linux system updates) from Python 3.7.4 to Python 3.9.2.在此期间,自从第一次使用该命令创建 Python 虚拟环境以来,我的系统 Python 已从 Python 3.7.4 升级(Arch Linux 系统更新)到 Python 3.9.2。

The solution is to use the command解决方法是使用命令

python -m venv <your_venv>  ## e.g. python -m ~/venv/ontology

When I did that ( python -m ... not python3 -m ... ), that venv now contained pip ...当我这样做时( python -m ...不是python3 -m ... ),venv 现在包含pip ...

To upgrade pip within that venv, use要在该 venv 中升级pip ,请使用

<your_venv_path>/bin/python -m pip install --upgrade pip

## e.g.
## /home/victoria/venv/ontology/bin/python -m pip install --upgrade pip

If you get "No module named pip" in ubuntu, try this.如果你在 ubuntu 中得到“No module named pip”,试试这个。

$python3 -m pip --version
/usr/bin/python3: No module named pip

$sudo apt-get install python3-pip

It worked for me.它对我有用。

After successful installation validate using安装成功后使用验证

$python3 -m pip --version

To upgrade to latest pip version升级到最新的 pip 版本

$python3 -m pip install --upgrade pip

I solved a similar error on Linux by setting PYTHONPATH to the site-packages location.我通过将 PYTHONPATH 设置为站点包位置解决了 Linux 上的类似错误。 This was after running python get-pip.py --prefix /home/chet/pip .这是在运行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)

my py version is 3.7.3, and this cmd worked我的 py 版本是 3.7.3,这个 cmd 有效

python3.7 -m pip install requests

requests library - for retrieving data from web APIs.请求库 - 用于从 Web API 检索数据。

This runs the pip module and asks it to find the requests library on PyPI.org (the Python Package Index) and install it in your local system so that it becomes available for you to import这将运行 pip 模块并要求它在 PyPI.org(Python 包索引)上找到 requests 库并将其安装在您的本地系统中,以便您可以导入

Tested below for Linux: You can directly download pip from https://pypi.org/simple/pip/ untar and use directly with your latest python.下面针对 Linux 进行了测试:您可以直接从https://pypi.org/simple/pip/ untar 下载 pip 并直接与您最新的 python 一起使用。

tar -xvf  pip-0.2.tar.gz
cd pip-0.2

Check for the contents.检查内容。

anant$ ls
docs  pip.egg-info  pip-log.txt  pip.py  PKG-INFO  regen-docs  scripts  setup.cfg  setup.py  tests

Execute directly:直接执行:

anant$ python pip.py --help
Usage: pip.py COMMAND [OPTIONS]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -E DIR, --environment=DIR
                        virtualenv environment to run pip in (either give the
                        interpreter or the environment base directory)
  -v, --verbose         Give more output
  -q, --quiet           Give less output
  --log=FILENAME        Log file where a complete (maximum verbosity) record
                        will be kept
  --proxy=PROXY         Specify a proxy in the form
                        user:passwd@proxy.server:port. Note that the
                        user:password@ is optional and required only if you
                        are behind an authenticated proxy.  If you provide
                        user@proxy.server:port then you will be prompted for a
                        password.
  --timeout=SECONDS     Set the socket timeout (default 15 seconds)

Here's a minimal set of instructions for upgrading to Python 3 using MacPorts:以下是使用 MacPorts 升级到 Python 3 的最小指令集:

sudo port install py37-pip
sudo port select --set pip pip37
sudo port select --set pip3 pip37
sudo pip install numpy, scipy, matplotlib

I ran some old code and it works again after this upgrade.我运行了一些旧代码,这次升级后它又可以工作了。

Followed the advise on this URL, to rename the python39._pth file.按照此 URL 上的建议重命名 python39._pth 文件。 That solved the issue这解决了问题

https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/#more-5606 https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/#more-5606

ren python39._pth python39._pth.save

我只需要用pip3替换pip所以我最终运行了如下命令: pip3 install matplotlib

I had a similar problem with virtualenv that had python3.8 while installing dependencies from requirements.txt file.我在从requirements.txt文件安装依赖python3.8时遇到了类似的问题, virtualenvpython3.8 I managed to get it to work by activating the virtualenv and then running the command python -m pip install -r requirements.txt and it worked.我设法通过激活virtualenv然后运行命令python -m pip install -r requirements.txt让它工作,它工作了。

Try to re-install the pip use curl command to download the get-pip.py file:尝试重新安装 pip 使用 curl 命令下载 get-pip.py 文件:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

if curl is not working then open this link : get-pip.py如果 curl 不起作用,请打开此链接: get-pip.py

create a get-pip.py file in your directory copy the code from this link and put it in the get-pip.py file and save the file in the same directory.在您的目录中创建一个 get-pip.py 文件,复制此链接中的代码并将其放入 get-pip.py 文件中,并将该文件保存在同一目录中。 then run the command然后运行命令

python get-pip.py

I am using Debian, but this solution can also be applied for Ubuntu.我使用的是 Debian,但此解决方案也适用于 Ubuntu。

  1. Usually, pip comes with python by default, in order to check if pip is installed in your system run.通常,pip 是默认自带python的,目的是检查你的系统运行中是否安装了pip。
 python -m pip --version
  1. If pip is not there, install it using Aptitude Linux Package Manager,如果 pip 不存在,请使用 Aptitude Linux Package Manager 安装它,
 # For Python 2 sudo apt install python-pip # For Python 3 sudo apt install python3-venv python3-pip
  1. I wouldn't use the get-pip.py script in Debian/Ubuntu, because in the documentation page mentions the following.我不会在 Debian/Ubuntu 中使用get-pip.py脚本,因为在文档页面中提到了以下内容。

Be cautious if you are using a Python install that is managed by your operating system or another package manager.如果您使用由操作系统或其他包管理器管理的 Python 安装,请务必小心。 get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. get-pip.py 不与这些工具协调,并且可能会使您的系统处于不一致的状态。

Sources here and there .来源在这里那里

运行 sudo apt-get install pip 并重试这个修复了我的问题的过程

for Windows:对于 Windows:

python -m ensurepip

after activate your env ex : venv激活您的 env ex 后:venv

(venv) PS D:\your path> d:\your path\venv\scripts\python.exe -m pip install --upgrade pip

sample of result:结果样本:

Collecting pip收集点子

Using cached pip-21.3-py3-none-any.whl (1.7 MB)使用缓存的 pip-21.3-py3-none-any.whl (1.7 MB)

Installing collected packages: pip安装收集的包:pip

Attempting uninstall: pip尝试卸载:pip

Found existing installation: pip 20.1.1

Uninstalling pip-20.1.1:

  Successfully uninstalled pip-20.1.1

Successfully installed pip-21.3成功安装 pip-21.3

For python2.7, download from https://bootstrap.pypa.io/pip/2.7/get-pip.py对于 python2.7,从https://bootstrap.pypa.io/pip/2.7/get-pip.py下载

then run然后运行

python get-pip.py

Steps to upgrade PIP in Windows (1) First, type Command Prompt in the Windows search box Windows中PIP升级步骤(一)首先,在Windows搜索框中输入Command Prompt

(2) Next, open the Command Prompt, and you'll see the following screen with your user name (to avoid any permission issues, you may consider to run the Command Prompt as an administrator): (2) 接下来,打开命令提示符,您将看到以下屏幕,显示您的用户名(为避免任何权限问题,您可以考虑以管理员身份运行命令提示符):

C:\\Users\\Ron> (3) In the Command Prompt, type “cd\\” to ensure that your starting point has only the drive name: C:\\Users\\Ron> (3) 在命令提示符中,键入“cd\\”以确保您的起点只有驱动器名称:

C:\\Users\\Ron>cd C:\\用户\\Ron>cd
(4) Press Enter, and you'll see the drive name C:> (4) 按回车,你会看到驱动器名称 C:>

C:> (5) Locate your Python application path, which is the folder where you originally installed Python. C:> (5) 找到你的 Python 应用程序路径,也就是你最初安装 Python 的文件夹。

Here is an example of a Python application path:以下是 Python 应用程序路径的示例:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39 C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39

(6) Once you retrieved the Python application path, type the following command in the Command Prompt: (6) 检索到 Python 应用程序路径后,在命令提示符中键入以下命令:

“cd” followed by your Python application path “cd”后跟您的 Python 应用程序路径

For our example:对于我们的示例:

C:>cd C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39 (7) Press Enter, and you'll see: C:>cd C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39 (7) 按回车,你会看到:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39> (8) To upgrade PIP, type\/copy this command, and then press Enter: C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39> (8) 要升级 PIP,请键入\/复制此命令,然后按 Enter:

python -m pip install --upgrade pip This is how the command would look like in the Command Prompt: python -m pip install --upgrade pip 这是命令在命令提示符中的样子:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39>python -m pip install ––upgrade pip (9) You'll notice that the latest version of PIP would be installed: C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39>python -m pip install ––upgrade pip (9) 你会注意到会安装最新版本的 PIP:

Successfully installed pip-21.1.1 Steps to check the version of PIP in Windows To check the version of PIP at any time, you'll need to use the Python Scripts path, rather than the Python application path.成功安装 pip-21.1.1 在 Windows 中检查 PIP 版本的步骤 要随时检查 PIP 的版本,您需要使用 Python 脚本路径,而不是 Python 应用程序路径。

(1) First, type “cd\\” to ensure that your starting point has only the drive name: (1) 首先,键入“cd\\”以确保您的起点只有驱动器名称:

C:\\Users\\Ron>cd C:\\用户\\Ron>cd
(2) Then, locate your Python Scripts path. (2) 然后,找到您的 Python 脚本路径。 The Scripts folder should be located within the Python application path. Scripts 文件夹应位于 Python 应用程序路径中。

For our example, the Python Scripts path is:对于我们的示例,Python 脚本路径是:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts

(3) Type “cd” followed by the Python Scripts path (then press Enter): (3) 键入“cd”,后跟 Python Scripts 路径(然后按 Enter):

C:>cd C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts (4) Finally, type the following command to check the version of PIP: C:>cd C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts (4) 最后输入以下命令查看PIP的版本:

pip --version For our example: pip --version 对于我们的示例:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts>pip ––version (5) Press Enter, and you'll see the PIP version: C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts>pip ––version (5) 回车,你会看到PIP版本:

pip 21.1.1 Now, what if you'd like to revert back to a previous version of PIP? pip 21.1.1 现在,如果您想恢复到以前的 PIP 版本怎么办?

You can easily downgrade to a previous version of PIP by following the steps below.您可以按照以下步骤轻松降级到以前版本的 PIP。

https:\/\/datatofish.com\/upgrade-pip\/<\/a> ----> will help you better https:\/\/datatofish.com\/upgrade-pip\/<\/a> ----> 会帮助你更好

"

python -m ensurepip --user python -m ensurepip --user

this if your mac is not above big sur如果你的 mac 不在 big sur 以上

and you installed py 3 -你安装了 py 3 -

I did this and I have no problems now我这样做了,我现在没有问题

back to the legacy version of 2.7 I guess.我猜想回到旧版 2.7。

I was facing the same error on win11, so the main problem was on executing pip command without admin permissions, so openup your terminal with administrator permission and then execute again the pip command.我在win11上遇到了同样的错误,所以主要问题是在没有管理员权限的情况下执行pip命令,所以用管理员权限打开你的终端,然后再次执行pip命令。 Hope it helps,希望能帮助到你,

For Windows:对于 Windows:

If pip is not available when Python is downloaded: run the command如果下载 Python 时pip不可用:运行命令

python get-pip.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM