378

OS: Mac OS X 10.7.5 (Lion)
Python ver: 2.7.5

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

I ran (sudo) python setup.py install in iTerm, output:

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 ran pip install and got the following error message:

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

How can I solve it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Lu
  • 3,781
  • 2
  • 13
  • 3
  • What happens when you run pip install from the terminal (not python interpreter) – TheoretiCAL Aug 21 '13 at 17:16
  • The terminal shows a error like "Import Error: No module named pip" – David Lu Aug 24 '13 at 10:24
  • I have counter the same question after update MacOSX. finally I found I setup pip failed. Reinstall pip and then fix it. – BollMose Dec 15 '13 at 10:59
  • you could refer http://stackoverflow.com/questions/10061039/importerror-no-module-named-pip-log-in-installation-using-pip?rq=1 – Jichao Feb 25 '15 at 14:37
  • 3
    Seems that will be not solution for You but I always try this command when I have some trouble with pip `python -m pip install ` – MartinP Jun 14 '16 at 22:51
  • 1
    HEADS UP: Systems that use Python for the system itself ship it without `pip` for a reason. *Manually installing `pip` and changing packages of the system Python can break your system in the worst case!* Unless you are absolutely positively sure that you need `pip` for the system Python, you need a *separate* Python instance – such as a venv or separate installation – which should ship with `pip` automatically these days. – MisterMiyagi Aug 29 '22 at 12:14
  • This has devolved into answers for both Linux and Windows. Isn't there a more canonical question (where answers for those platforms could go instead)? – Peter Mortensen Aug 06 '23 at 22:53

31 Answers31

363

My solution for a Ubuntu machine:

For Python 3

sudo apt install python3-pip

For Python 2

sudo apt install python-pip
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 171
    the question is about installing on Mac. – Corey Goldberg May 25 '17 at 02:14
  • 5
    On Arch I had to install python2-pip, python-pip pointed to python3 – Florian Brinker Mar 12 '18 at 14:45
  • 1
    OMG thank you! I have a vagrant box spun up with python 3 and was wondering why pip commands where not working when I installed pip via 'sudo apt-get install python-pip'. These versioning changes (i.e. like php with homebrew) drive me crazy sometimes... – Ryan Coolwebs Dec 12 '18 at 02:58
  • `sudo yum install -y python38-pip` worked! Thanks.. –  Nov 16 '21 at 08:42
  • `Package python-pip is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: python3-pip E: Package 'python-pip' has no installation candidate` and `E: Unable to locate package python2-pip` per Florian's suggestion – Drake P Feb 22 '22 at 03:21
327

With macOS v10.15 (Catalina) 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kainjow
  • 3,955
  • 1
  • 20
  • 17
  • 7
    In Ubuntu I get "ensurepip is disabled in Debian/Ubuntu for the system python". I solved with `sudo apt install python3-pip` – tuxErrante Nov 18 '19 at 13:56
  • 33
    Works also under Windows! After saying `pip install --upgrade pip` my pip was gone (because pip was uninstalled sucessfully but failed to reinstall because pip.exe was busy...). `python -m ensurepip` brought back the default pip, from where I could take the correct upgrade path `python -m pip install --upgrade pip` – Adrian W Nov 30 '20 at 22:49
  • Thank you so much, this helped me fix this issue on WIndows without reinstalling python. – Maksym Shcherban Oct 18 '21 at 20:24
  • 12
    The working command for me in windows was `python -m ensurepip` – Daniel Oct 29 '21 at 19:10
  • 2
    worked on Ubuntu – Aadam Mar 22 '22 at 09:12
  • This failed for me on Windows (`ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied`). Using an administrator prompt worked though. – ggorlen Feb 25 '23 at 05:48
  • Worked on Almalinux 9 – Criminally Inane Jul 13 '23 at 08:21
237

On Mac, using Homebrew (executable brew) is a better option as apt-get is not available.

Command:

brew install python

In case you have both Python 2 and Python 3 installed on the 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
iosCurator
  • 4,356
  • 2
  • 21
  • 25
  • 7
    Oh finally a working solution! Thanks! I needed python3 on Mac (Mac OS X 10.13.4). After installing python with **Brew** `brew install python` the **pip** was not found: `python3 -m pip install redis` resulted in pip not found. Following your approach (python3 -m ...) did the trick. – Raipe May 17 '18 at 05:13
  • 1
    I am having python2 and 3 on the same machine but for now I wanted to use Python3. Hence I had to modify the comment above to `sudo python3 -m pip install matplotlib` (I had to do this via sudo, otherwise some folder permission didnt work). (edited the answer correspondingly) – SCBuergel Jan 05 '19 at 07:55
  • 1
    This worked for me, just remember to add a `sudo` at the beginning. – vicegax Jan 07 '21 at 09:59
  • When running the second command I get: "zipimport.ZipImportError: can't decompress data; zlib not available" – Nermin Mar 10 '21 at 07:14
  • @vicegax No, do not use `sudo` with pip. You should not be modifying OS Python installation with extra libraries. Learn to use `venv` – OneCricketeer Apr 04 '23 at 18:23
79

For Windows:

python -m ensurepip

After activating your environment. Example: venv

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

Sample of a 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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fethi Pounct
  • 1,059
  • 5
  • 6
  • 2
    Thanks **python -m ensurepip** saved my life. After Ubuntu upgrade (on production from 21 to 22), no more modules in my `venv` => **error 500**. Apache logs said : "no module named django". Also `PIP` seemed to be not installed. After **ensurepip** in my VENV , I just ran `pip install -r requirements.txt` (because `pip freeze` was returning an empty result) and all my modules went back. Site if live again. Thanks @Fethi Pounct. If you want to know what's **ensurepip** , have a look [here](https://docs.python.org/3/library/ensurepip.html) – Abpostman1 Dec 08 '22 at 11:49
65

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

easy_install pip
Manu
  • 3,212
  • 1
  • 16
  • 14
29

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
AllisLove
  • 439
  • 4
  • 11
  • 2
    This worked for me, but for python2, the according link is this: https://bootstrap.pypa.io/pip/2.7/get-pip.py – Mayak Jul 05 '21 at 09:58
  • 1
    https://linuxize.com/post/how-to-install-pip-on-ubuntu-20.04/ – Gery Mar 28 '23 at 19:46
  • What is *pypa.io*? Is it reputable? The answer ought to address it, but *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***[without](https://meta.stackexchange.com/a/131011)*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** "Edit:", "Update:", or similar - the answer should appear as if it was written today. – Peter Mortensen Aug 06 '23 at 22:02
28

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
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Qiangzini
  • 527
  • 6
  • 8
18

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)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ANUP SAJJAN
  • 1,458
  • 13
  • 17
12

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
    
  2. Initialise a new virtualenv

    virtualenv venv
    . venv/bin/activate
    
  3. Install the new requirements then worked:

    pip install -r src/requirements.txt
    
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Marcello Romani
  • 2,967
  • 31
  • 40
  • 1
    Deactivating and reactivating worked for me. Thanks. – arn-arn Jan 18 '23 at 16:24
  • 1
    This was the trick for me as well. You can tell if the version you get when you run `python --version` is a different Major/Minor than what's in your `$VIRTUAL_ENV/lib/` directory. – AC Capehart Mar 23 '23 at 16:43
8

Use:

python -m ensurepip --user

This if your Mac is not above macOS v11 (Big Sur) and you installed Python 3. I did this and I don't have any problems now. Back to the legacy version of 2.7 I guess.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark Antony
  • 91
  • 2
  • 1
  • https://apple.stackexchange.com/questions/425192/i-am-trying-to-install-pip-on-terminal-and-i-always-get-this-error – Mark Antony Aug 21 '22 at 22:25
7

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
7

If you get "No module named pip" in Ubuntu, try this:

python3 -m pip --version

Output:

/usr/bin/python3: No module named pip

And:

sudo apt-get install python3-pip

It worked for me.

After successful installation, validate using

python3 -m pip --version

To upgrade to the latest pip version

python3 -m pip install --upgrade pip
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Vijay
  • 79
  • 1
  • 1
  • when trying this I get `Both /lib/terminfo/w/wsvt25m and /usr/lib/terminfo/w/wsvt25m exist`, any idea? I am using Ubuntu under WSL2 (Windows) – Itamar Katz Nov 23 '22 at 07:26
6

I ran into this same issue when I attempted to install the Nova client (as root).

python  setup.py install

Output:

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.

brew search pip

Output:

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

And:

sudo easy_install pip

The commands should be similar if you use MacPorts.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
spuder
  • 17,437
  • 19
  • 87
  • 153
5

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
5

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lava Sangeetham
  • 2,943
  • 4
  • 38
  • 54
4

I think none of the previous answers 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sudoz
  • 3,275
  • 1
  • 21
  • 19
4

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
meaning-matters
  • 21,929
  • 10
  • 82
  • 142
ScottyC
  • 1,467
  • 1
  • 15
  • 22
  • 1
    I had Xcode already installed. Did `ruby ...` and `brew ...`. When running `pip ...` I got `-bash: pip: command not found`. Any ideas? – meaning-matters Dec 27 '17 at 18:21
3

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

MadeOfAir
  • 2,933
  • 5
  • 31
  • 39
3

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Victoria Stuart
  • 4,610
  • 2
  • 44
  • 37
2

In a 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 or pip2.7 in my case works, and pip.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Artem Zinoviev
  • 869
  • 12
  • 32
2

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.

Georgios Syngouroglou
  • 18,813
  • 9
  • 90
  • 92
2

It is very likely that the pip package was unsuccessfully updated. You need to remove and recreate the virtual environment.

Deactivate and remove the virtual environment:

deactivate
rm -rf [virtual_environment_name]

Create a new one

python -m venv venv_name

Activate it

source ./venv_name/Scripts/activate

Install the package you want:

pip install [package_name]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abdel
  • 69
  • 3
1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
StevenJD
  • 77
  • 6
1

I was facing the same error on Windows 11, so the main problem was on executing the pip command without administrator permissions, so open up your terminal with administrator permissions and then execute the pip command again.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

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)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
GargantuChet
  • 5,691
  • 1
  • 30
  • 41
0

Tested below for Linux:

You can directly download pip from https://pypi.org/simple/pip/, untar, and use directly with your latest Python installation.

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

Check for the contents:

ls

Output:

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

Execute directly:

python pip.py --help

Output:

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)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahesh Revaskar
  • 106
  • 1
  • 5
0

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

0

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.

Asim
  • 543
  • 4
  • 20
-1

My Python version is 3.7.3, and this command 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahi
  • 472
  • 5
  • 7
-3

For Windows:

If pip is not available when Python is downloaded: run the command

python get-pip.py

MarianD
  • 13,096
  • 12
  • 42
  • 54
KavithaV
  • 27
  • 3