English 中文(简体)
ImportError: No module named pip
原标题:

OS: Mac OS X 10.7.5 Python Ver: 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.

Run (sudo) python setup.py install in iTerm shows that

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

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?

问题回答

My solution for Ubuntu machine:

For Python 3

sudo apt install python3-pip

For Python 2

sudo apt install python-pip

With macOS 10.15 and Homebrew 2.1.6 I was getting this error with Python 3.7. I just needed to run:

python3 -m ensurepip

Now python3 -m pip works for me.

On Mac using brew is a better option as apt-get is not available.

Command:

brew install python

In case you have both python2 & python3 installed on machine

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.

for Windows:

python -m ensurepip

after activate your env ex : venv

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

sample of result:

Collecting pip

  Using cached pip-21.3-py3-none-any.whl (1.7 MB)

Installing collected packages: pip

  Attempting uninstall: pip

    Found existing installation: pip 20.1.1

    Uninstalling pip-20.1.1:

      Successfully uninstalled pip-20.1.1

Successfully installed pip-21.3

After installing ez_setup, you should have easy_install available. To install pip just do:

easy_install pip

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

python get-pip.py

Try to install pip through Python:

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

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

python get-pip.py

On some kind of Linux, like distributions based on Debian, you might want to consider updating your apt-get first, in case you are installing python-pip through it.

sudo apt-get update

This might help apt-get to update its indexes and locate the python-pip package. After this, you might install pip like this:

sudo apt-get install python-pip (Python 2)
sudo apt-get install python3-pip (Python 3)

I encountered the same error with Python 3.8.6 on macOS v11 (Big Sur).

Whether I used pip or pip3, I d get this error:

 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. This fixed the issue for me:

  1. Remove the old virtualenv
deactivate
rm -rf venv
  1. Initialise a new virtualenv
virtualenv venv
. venv/bin/activate
  1. Install the new requirements then worked:
pip install -r src/requirements.txt

Try to re-install the pip use curl command to download the get-pip.py file:

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

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. then run the command

python get-pip.py

If you get "No module named pip" in ubuntu, try this.

$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

$python3 -m pip install --upgrade pip

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

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

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.

python -m ensurepip --user 

This if your mac is not above big sur and you installed py 3. I did this and I have no problems now. Back to the legacy version of 2.7 I guess.

Download:

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

Then Install pip:

py get-pip.py

Then Install any module, such as biopython:

py -m pip install biopython

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

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

Install Xcode if not already:

xcode-select –install

Install Brew as described here:

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

Then install Python through Brew:

brew install python

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

pip install pyserial

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)

after that, just pip install <your package>. The error will be gone.

Python3

curl -sS https://bootstrap.pypa.io/get-pip.py | python3
python3 -m pip install --upgrade pip

Just replace the python version you want in the above commands

For python 3.11 specific install

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
python3.11 -m pip install --upgrade pip

For python 3.10 specific install

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
python3.10 -m pip install --upgrade pip

For python2.7

curl -sS https://bootstrap.pypa.io/pip/2.7/get-pip.py | python2.7
python2.7 -m pip install --upgrade pip

I downloaded pip binaries from here and it resolved the issue.

I encountered the issue ModuleNotFoundError: No module named pip when I created a new Python 3 virtual environment using the command

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.

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.

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 ...

To upgrade pip within that venv, use

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

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

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

I am using Debian, but this solution can also be applied for Ubuntu.

  1. Usually, pip comes with python by default, in order to check if pip is installed in your system run.
python -m pip --version
  1. If pip is not there, install it using 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.

Be cautious if you are using a Python install that is managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state.

Sources here and there.

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. Hope it helps,

Here s a minimal set of instructions for upgrading to Python 3 using MacPorts:

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

I ran some old code and it works again after this upgrade.

I just needed to replace pip with pip3 so I ended up running the command as follows: pip3 install matplotlib

I had a similar problem with virtualenv that had python3.8 while installing dependencies from requirements.txt file. 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.

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.

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

Tested below for Linux:

You can directly download pip from https://pypi.org/simple/pip/ untar and use directly with your latest 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)

I followed the advice on this URL, to rename the python39._pth file. That solved the issue

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

ren python39._pth python39._pth.save

my py version is 3.7.3, and this cmd worked

python3.7 -m pip install requests

requests library - for retrieving data from web APIs.

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





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签