Module not found error 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...

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?

Fredrick Gauss's user avatar

asked Aug 21, 2013 at 16:34

David Lu's user avatar

6

I had the same problem.
My solution:

For Python 3

sudo apt-get install python3-pip

For Python 2

sudo apt-get install python-pip

lmiguelvargasf's user avatar

answered Jun 14, 2016 at 8:15

5

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.

answered Jul 5, 2019 at 3:14

kainjow's user avatar

kainjowkainjow

3,3551 gold badge19 silver badges17 bronze badges

6

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.

Jonathan Cabrera's user avatar

answered Oct 8, 2017 at 12:17

iosCurator's user avatar

iosCuratoriosCurator

4,2762 gold badges21 silver badges25 bronze badges

4

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

easy_install pip

answered Oct 27, 2014 at 14:21

Manu's user avatar

ManuManu

3,0631 gold badge15 silver badges14 bronze badges

4

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

answered Oct 20, 2021 at 23:42

Fethi Pounct's user avatar

1

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

answered Nov 29, 2020 at 16:52

AllisLove's user avatar

AllisLoveAllisLove

3892 silver badges11 bronze badges

1

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.

sudo apt-get update

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

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

answered Apr 21, 2020 at 18:23

ANUP SAJJAN's user avatar

ANUP SAJJANANUP SAJJAN

1,38812 silver badges17 bronze badges

1

I encountered the same error with Python 3.8.6 on MacOS 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

answered Jan 21, 2021 at 15:49

Marcello Romani's user avatar

1

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

answered Apr 12, 2021 at 10:12

Deepesh ranjan's user avatar

2

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

answered Jun 2, 2021 at 1:58

Vijay's user avatar

VijayVijay

791 silver badge1 bronze badge

1

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.

answered Sep 9, 2013 at 19:22

spuder's user avatar

spuderspuder

16.8k19 gold badges86 silver badges149 bronze badges

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's user avatar

answered Aug 31, 2016 at 18:03

ScottyC's user avatar

ScottyCScottyC

1,4071 gold badge15 silver badges22 bronze badges

1

Download:

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

Then Install pip:

py get-pip.py

Then Install biopython:

py -m pip install biopython

I wish it would be useful

answered Mar 15, 2021 at 9:31

Khaled Al Halabee's user avatar

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

answered Jun 11, 2014 at 8:51

MadeOfAir's user avatar

MadeOfAirMadeOfAir

2,8734 gold badges29 silver badges39 bronze badges

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 sudo pip install Django.
The error will be gone.

The Red Pea's user avatar

The Red Pea

16.7k18 gold badges97 silver badges127 bronze badges

answered Oct 28, 2015 at 13:59

sudoz's user avatar

sudozsudoz

3,1251 gold badge21 silver badges19 bronze badges

1

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

answered Apr 5, 2021 at 16:50

Victoria Stuart's user avatar

Victoria StuartVictoria Stuart

4,3762 gold badges41 silver badges36 bronze badges

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

answered Oct 27, 2014 at 13:55

Artem Zinoviev's user avatar

0

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.

answered Apr 15, 2021 at 5:36

Georgios Syngouroglou's user avatar

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.

answered Aug 21, 2022 at 22:25

Mark Antony's user avatar

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
sudo pip install numpy, scipy, matplotlib

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

grooveplex's user avatar

grooveplex

2,4524 gold badges28 silver badges30 bronze badges

answered Oct 16, 2019 at 19:58

StevenJD's user avatar

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,

answered Aug 31, 2022 at 13:06

Marielys Brijaldo's user avatar

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)

answered Oct 24, 2017 at 21:54

GargantuChet's user avatar

GargantuChetGargantuChet

5,6111 gold badge30 silver badges41 bronze badges

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)

answered Oct 1, 2019 at 10:42

Anant Bhasu's user avatar

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

answered Oct 1, 2020 at 20:42

Ben Calvert's user avatar

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.

answered Oct 16, 2020 at 5:44

Asim's user avatar

AsimAsim

5234 silver badges18 bronze badges

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

answered May 1, 2019 at 13:25

Mahi's user avatar

MahiMahi

4625 silver badges7 bronze badges

1

For Windows:

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

python get-pip.py

MarianD's user avatar

MarianD

12.4k12 gold badges39 silver badges53 bronze badges

answered Feb 10, 2021 at 15:00

KavithaV's user avatar

Environment

  • pip version: 9.0.3
  • Python version: 3.6
  • OS: Windows Server 2016 Datacenter

Description
My system admin installed Python 3.6 for me in my AWS workspace and i requested him to update the pip version to 18 but while he was trying to upgrade the version, he ran into error. All below-mentioned commands were executed from a Powershell window in Administrative mode:

Output

PS D:python3.6scripts> pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940
/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 720kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
Exception:
Traceback (most recent call last):
  File "d:python3.6libshutil.py", line 544, in move
    os.rename(src, real_dst)
OSError: [WinError 17] The system cannot move the file to a different disk drive: 'd:\python\3.6\scripts\pip.exe' ->
 'C:\Users\sdgadmin\AppData\Local\Temp\pip-o9ithn08-uninstall\python\3.6\scripts\pip.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:python3.6libsite-packagespipbasecommand.py", line 215, in main
  File "d:python3.6libsite-packagespipcommandsinstall.py", line 342, in run
  File "d:python3.6libsite-packagespipreqreq_set.py", line 778, in install
  File "d:python3.6libsite-packagespipreqreq_install.py", line 754, in uninstall
  File "d:python3.6libsite-packagespipreqreq_uninstall.py", line 115, in remove
  File "d:python3.6libsite-packagespiputils__init__.py", line 267, in renames
  File "d:python3.6libshutil.py", line 559, in move
    os.unlink(src)
PermissionError: [WinError 5] Access is denied: 'd:\python\3.6\scripts\pip.exe'

PS D:python3.6scripts> pip list
Traceback (most recent call last):
  File "d:python3.6librunpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:python3.6librunpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:Python3.6Scriptspip.exe__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'

PS D:python3.6scripts> pip3 install --upgrade pip
Traceback (most recent call last):
  File "d:python3.6librunpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:python3.6librunpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:Python3.6Scriptspip3.exe__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'

PS D:python3.6scripts> pip3 install --upgrade pip3
Traceback (most recent call last):
  File "d:python3.6librunpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:python3.6librunpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:Python3.6Scriptspip3.exe__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'

PS D:python3.6scripts> pip install --upgrade pip
Traceback (most recent call last):
  File "d:python3.6librunpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:python3.6librunpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:Python3.6Scriptspip.exe__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'

PS D:python3.6scripts> pip.exe install --upgrade pip
Traceback (most recent call last):
  File "d:python3.6librunpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:python3.6librunpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:Python3.6Scriptspip.exe__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'

Are we doing something wrong here? I also checked few links that suggested using easy_install. I tried that as well but ran into issues.

PS D:python3.6scripts> .easy_install.exe pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
d:python3.6libsite-packagessetuptoolspep425tags.py:89: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python
 ABI tag may be incorrect
  warn=(impl == 'cp')):
d:python3.6libsite-packagessetuptoolspep425tags.py:93: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, P
ython ABI tag may be incorrect
  warn=(impl == 'cp')):
Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/p
ip-18.0-py2.py3-none-any.whl#sha256=070e4bf493c7c2c9f6a08dd797dd3c066d64074c38e9e8a0fb4e6541f266d96c
error: Download error for https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3
703d2ddaf940/pip-18.0-py2.py3-none-any.whl#sha256=070e4bf493c7c2c9f6a08dd797dd3c066d64074c38e9e8a0fb4e6541f266d96c: [SSL
: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)

This error occurs when you try to use pip, but it is not installed in your Python environment. This can happen if you skip installing pip when installing Python or when creating a virtual environment, or after explicitly uninstalling pip.

You can solve this error by downloading pip using the following curl command

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

Then install pip by running:

python3 get-pip.py

If this does not work, you can use ensurepip to bootstrap the pip installer into an existing Pip installation or virtual environment. For example,

# Linux
python3 -m ensurepip --upgrade

# MacOS
python3 -m ensurepip --upgrade

# Windows
py -m ensurepip --upgrade

This tutorial will go through the ways to ensure pip is installed in your environment.


Table of contents

  • Install pip by Downloading get-pip.py
  • Bootstrap pip using ensurepip
  • Install pip using Operating System Specific command
    • Installing pip for Linux
    • Installing pip for Mac Operating System
  • Upgrading pip
  • Check pip and Python version
  • Recreate Virtual Environment
  • Summary

Install pip by Downloading get-pip.py

Download pip by running the following curl command:

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

The curl command allows you to specify a direct download link. Using the -o option sets the name of the downloaded file.

Install pip by running:

python3 get-pip.py

Bootstrap pip using ensurepip

You can use ensurepip to bootstrap the pip installer into an existing Pip installation or virtual environment. For example,

# Linux
python3 -m ensurepip --upgrade

# MacOS
python3 -m ensurepip --upgrade

# Windows
py -m ensurepip --upgrade

Install pip using Operating System Specific command

If the above solutions do not work, you can try to install pip using the command specific to your operating system.

Installing pip for Linux

All major Linux distributions have Python installed by default. However, you will need to install pip. You can install pip from the terminal, but the installation instructions depend on the Linux distribution you are using. You will need root privileges to install pip. Open a terminal and use the commands relevant to your Linux distribution to install pip.

Installing pip for Ubuntu, Debian, and Linux Mint

sudo apt install python-pip3

Installing pip for CentOS 8 (and newer), Fedora, and Red Hat

sudo dnf install python-pip3

Installing pip for CentOS 6 and 7, and older versions of Red Hat

sudo yum install epel-release

sudo yum install python-pip3

Installing pip for Arch Linux and Manjaro

sudo pacman -S python-pip

Installing pip for OpenSUSE

sudo zypper python3-pip

Installing pip for Mac Operating System

You can install Python3 and pip3 using brew with the following command:

brew install python

Upgrading pip

You may also need to upgrade pip, which you can do with the following commands:

# Linux
python3 -m pip install --upgrade pip

# MacOS
python3 -m pip install --upgrade pip

# Windows
py -m pip install --upgrade pip

Check pip and Python version

Ensure that the Python version in use matches the pip version. You can check versions from the command line using the --version flag. For example,

python --version
Python 3.8.8
pip --version
pip 21.2.4 from /Users/Research/opt/anaconda3/lib/python3.8/site-packages/pip (python 3.8)

Note that the –version returns the version of Python is 3.8.8, and the pip installer in use is for 3.8.

Recreate Virtual Environment

If you are using a virtual environment and the error persists despite trying the above solutions, you can recreate the environment. For example,

# deactivate environment

deactivate

# remove the virtual environment folder

rm -rf venv

# Initial a new virtual environment

python3 -m venv venv

# Activate on Linux/MacOS

source venv/bin/activate

# Activate on Windows (cmd.exe)

venvScriptsactivate.bat

# Activate on Windows (PowerShell)

venvScriptsActivate.ps1

Summary

Congratulations on reading to the end of this tutorial.

Go to the online courses page on Python to learn more about Python for data science and machine learning.

For further reading on missing modules in Python, go to the article:

  • How to Solve ModuleNotFoundError: no module named ‘plotly’.
  • How to Solve Python ModuleNotFoundError: no module named ‘pymongo’
  • How to Solve Python ModuleNotFoundError: no module named ‘xgboost’

Have fun and happy researching!

In this article, we will look into how to solve «/usr/bin/python3: No module named pip» error which I believe is a pretty common error in a freshly built Linux System where python3 packages are not installed yet. pip is a very famous python package management tool frequently used by Python Programmers and developers to manage their application packages. If you don’t have pip installed before you are trying to install any of the python modules then you will always end up with "/usr/bin/python3: No module named pip" error just like what I encountered last night. While this may not be the only reason to have this error but this is the common most reason for lot of folks !!

Solved: "/usr/bin/python3: No module named pip" error on Linux

Also Read: How to Check and Log Malicious RPM Installation in 3 Easy Steps

So when I was trying to install a package using pip, I encountered below error in my Ubuntu 20.04 LTS System. You might be getting the same error in different Linux version.

root@cyberithub:~# python3 -m pip install --user pipenv
/usr/bin/python3: No module named pip

While this error can come due to multiple reasons but in most of the cases you will see this error because of pip package not installed in your System. So to solve this kind of error, you need to simply install pip package from the default Repo. For example, in my case I have used apt-get install python3-pip command to install this package in my System. More about PIP.

NOTE:

Please note that here I am using root user to run all the below commands. You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

root@cyberithub:~# apt-get install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
dmeventd libaio1 libdevmapper-event1.02.1 liblvm2cmd2.03 libreadline5 thin-provisioning-tools
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu build-essential dpkg-dev fakeroot g++ g++-9 gcc gcc-9 libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcrypt-dev libctf-nobfd0 libctf0 libexpat1-dev libfakeroot libgcc-9-dev
libitm1 liblsan0 libpython3-dev libpython3.8-dev libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev python-pip-whl
python3-dev python3-distutils python3-setuptools python3-wheel python3.8-dev zlib1g-dev
Suggested packages:
binutils-doc debian-keyring g++-multilib g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison gcc-doc gcc-9-multilib gcc-9-locales
glibc-doc libstdc++-9-doc make-doc python-setuptools-doc
The following NEW packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu build-essential dpkg-dev fakeroot g++ g++-9 gcc gcc-9 libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcrypt-dev libctf-nobfd0 libctf0 libexpat1-dev libfakeroot libgcc-9-dev
libitm1 liblsan0 libpython3-dev libpython3.8-dev libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev python-pip-whl
python3-dev python3-distutils python3-pip python3-setuptools python3-wheel python3.8-dev zlib1g-dev
0 upgraded, 43 newly installed, 0 to remove and 171 not upgraded.
Need to get 41.7 MB of archives.
After this operation, 185 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
........................................

If you are using RHEL/CentOS 7 based Systems, then all you need to do in to enable the EPEL Repo and then install the package by using yum install python3-pip command. For RHEL/CentOS 8 based Systems, you can use dnf install python3-pip command.

yum install python3-pip 
dnf install python3-pip

After successful installation, you can verify the package version by using pip --version command as shown below.

root@cyberithub:~# pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

After installing the package I again tried to run the earlier command then this time I noticed that the command worked successfully and now it is not throwing "/usr/bin/python3: No module named pip" error as shown below. Hope this helps !!

root@cyberithub:~# python3 -m pip install --user pipenv
Collecting pipenv
Downloading pipenv-2022.1.8-py2.py3-none-any.whl (3.6 MB)
|████████████████████████████████| 3.6 MB 1.4 MB/s
Requirement already satisfied: pip>=18.0 in /usr/lib/python3/dist-packages (from pipenv) (20.0.2)
Collecting virtualenv
Downloading virtualenv-20.13.2-py2.py3-none-any.whl (8.7 MB)
|████████████████████████████████| 8.7 MB 11.2 MB/s
Collecting virtualenv-clone>=0.2.5
Downloading virtualenv_clone-0.5.7-py3-none-any.whl (6.6 kB)
Requirement already satisfied: certifi in /usr/lib/python3/dist-packages (from pipenv) (2019.11.28)
Requirement already satisfied: setuptools>=36.2.1 in /usr/lib/python3/dist-packages (from pipenv) (45.2.0)
Requirement already satisfied: six<2,>=1.9.0 in /usr/lib/python3/dist-packages (from virtualenv->pipenv) (1.14.0)
Collecting distlib<1,>=0.3.1
Downloading distlib-0.3.4-py2.py3-none-any.whl (461 kB)
|████████████████████████████████| 461 kB 16.4 MB/s
Collecting filelock<4,>=3.2
Downloading filelock-3.6.0-py3-none-any.whl (10.0 kB)
Collecting platformdirs<3,>=2
Downloading platformdirs-2.5.1-py3-none-any.whl (14 kB)
Installing collected packages: distlib, filelock, platformdirs, virtualenv, virtualenv-clone, pipenv
WARNING: The script virtualenv is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script virtualenv-clone is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts pipenv and pipenv-resolver are installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed distlib-0.3.4 filelock-3.6.0 pipenv-2022.1.8 platformdirs-2.5.1 virtualenv-20.13.2 virtualenv-clone-0.5.7

Quick Fix: Python raises the ImportError: No module named 'pip' when it cannot find the library pip. The most frequent source of this error is that you haven’t installed pip explicitly with pip install pip. Alternatively, you may have different Python versions on your computer, and pip is not installed for the particular version you’re using.

Problem Formulation

You’ve just learned about the awesome capabilities of the pip library and you want to try it out, so you start your code with the following statement:

import pip

This is supposed to import the Pandas library into your (virtual) environment. However, it only throws the following ImportError: No module named pip:

>>> import pip
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    import pip
ModuleNotFoundError: No module named 'pip'

Solution Idea 1: Install Library pip

The most likely reason is that Python doesn’t provide pip in its standard library. You need to install it first!

Before being able to import the Pandas module, you need to install it using Python’s package manager pip. Make sure pip is installed on your machine.

To fix this error, you can run the following command in your Windows shell:

$ pip install pip

This simple command installs pip in your virtual environment on Windows, Linux, and MacOS. It assumes that your pip version is updated. If it isn’t, use the following two commands in your terminal, command line, or shell (there’s no harm in doing it anyways):

$ python -m pip install --upgrade pip
$ pip install pandas

💡 Note: Don’t copy and paste the $ symbol. This is just to illustrate that you run it in your shell/terminal/command line.

Solution Idea 2: Fix the Path

The error might persist even after you have installed the pip library. This likely happens because pip is installed but doesn’t reside in the path you can use. Although pip may be installed on your system the script is unable to locate it. Therefore, it is unable to install the library using pip in the correct path.

To fix the problem with the path in Windows follow the steps given next.

Step 1: Open the folder where you installed Python by opening the command prompt and typing where python

Step 2: Once you have opened the Python folder, browse and open the Scripts folder and copy its location. Also verify that the folder contains the pip file.

Step 3: Now open the Scripts directory in the command prompt using the cd command and the location that you copied previously.

Step 4: Now install the library using pip install pip command. Here’s an analogous example:

After having followed the above steps, execute our script once again. And you should get the desired output.

Other Solution Ideas

  • The ModuleNotFoundError may appear due to relative imports. You can learn everything about relative imports and how to create your own module in this article.
  • You may have mixed up Python and pip versions on your machine. In this case, to install pip for Python 3, you may want to try python3 -m pip install pip or even pip3 install pip instead of pip install pip
  • If you face this issue server-side, you may want to try the command pip install --user pip
  • If you’re using Ubuntu, you may want to try this command: sudo apt install pip
  • You can check out our in-depth guide on installing pip here.
  • You can also check out this article to learn more about possible problems that may lead to an error when importing a library.

Understanding the “import” Statement

import pip

In Python, the import statement serves two main purposes:

  • Search the module by its name, load it, and initialize it.
  • Define a name in the local namespace within the scope of the import statement. This local name is then used to reference the accessed module throughout the code.

What’s the Difference Between ImportError and ModuleNotFoundError?

What’s the difference between ImportError and ModuleNotFoundError?

Python defines an error hierarchy, so some error classes inherit from other error classes. In our case, the ModuleNotFoundError is a subclass of the ImportError class.

You can see this in this screenshot from the docs:

You can also check this relationship using the issubclass() built-in function:

>>> issubclass(ModuleNotFoundError, ImportError)
True

Specifically, Python raises the ModuleNotFoundError if the module (e.g., pip) cannot be found. If it can be found, there may be a problem loading the module or some specific files within the module. In those cases, Python would raise an ImportError.

If an import statement cannot import a module, it raises an ImportError. This may occur because of a faulty installation or an invalid path. In Python 3.6 or newer, this will usually raise a ModuleNotFoundError.

Related Videos

The following video shows you how to resolve the ImportError:

How to Fix : “ImportError: Cannot import name X” in Python?

The following video shows you how to import a function from another folder—doing it the wrong way often results in the ModuleNotFoundError:

How to Call a Function from Another File in Python?

How to Fix “ModuleNotFoundError: No module named ‘pip’” in PyCharm

If you create a new Python project in PyCharm and try to import the pip library, it’ll raise the following error message:

Traceback (most recent call last):
  File "C:/Users/.../main.py", line 1, in <module>
    import pip
ModuleNotFoundError: No module named 'pip'

Process finished with exit code 1

The reason is that each PyCharm project, per default, creates a virtual environment in which you can install custom Python modules. But the virtual environment is initially empty—even if you’ve already installed pip on your computer!

Here’s a screenshot exemplifying this for the pandas library. It’ll look similar for pip.

The fix is simple: Use the PyCharm installation tooltips to install Pandas in your virtual environment—two clicks and you’re good to go!

First, right-click on the pandas text in your editor:

Second, click “Show Context Actions” in your context menu. In the new menu that arises, click “Install Pandas” and wait for PyCharm to finish the installation.

The code will run after your installation completes successfully.

As an alternative, you can also open the Terminal tool at the bottom and type:

$ pip install pip

If this doesn’t work, you may want to set the Python interpreter to another version using the following tutorial: https://www.jetbrains.com/help/pycharm/2016.1/configuring-python-interpreter-for-a-project.html

You can also manually install a new library such as pip in PyCharm using the following procedure:

  • Open File > Settings > Project from the PyCharm menu.
  • Select your current project.
  • Click the Python Interpreter tab within your project tab.
  • Click the small + symbol to add a new library to the project.
  • Now type in the library to be installed, in your example Pandas, and click Install Package.
  • Wait for the installation to terminate and close all popup windows.

Here’s an analogous example:

Here’s a full guide on how to install a library on PyCharm.

  • How to Install a Library on PyCharm

Nerd Humor

Oh yeah, I didn’t even know they renamed it the Willis Tower in 2009, because I know a normal amount about skyscrapers. — xkcd (source)

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.

To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.

His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.

I installed Python 3.4 on CentOS 7.3:

sudo yum install epel-release
sudo yum install python34.x86_64

There was python 2 installed before under

type python
python is hashed (/bin/python)

So version 3 is under python3:

type python3
python3 is hashed (/bin/python3)

On Windows, I have version 3.5 and the way I install packages is:

python -m pip install <package_name>

So I tried the same on CentOS but calling python3 instead of python:

python3 -m pip install psycopg2
/bin/python3: No module named pip

How do I install or enable pip in Python 3.4 on CentOS so that I can install packages?

asked Feb 17, 2017 at 16:54

amphibient's user avatar

1

Enable epl-repo:

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
rpm -ivh epel-release-7-9.noarch.rpm

Install pip:

sudo yum --enablerepo=epel install python-pip
pip install -U pip

Enable Software Collections:

sudo yum install centos-release-scl
sudo yum install scl-utils-build
sudo yum-config-manager --enable rhel-server-rhscl-7-rpms

Install the rh-python34 collection.

sudo yum install rh-python34
scl enable rh-python34 bash

Install PostgreSQL development header files and libraries:

sudo yum install postgresql-devel

Install Python development header files and libraries:

sudo yum install python-devel

Install your package:

python3 -m pip install psycopg2

amphibient's user avatar

amphibient

12k18 gold badges61 silver badges87 bronze badges

answered Feb 17, 2017 at 18:41

GAD3R's user avatar

GAD3RGAD3R

60.9k30 gold badges126 silver badges189 bronze badges

9

Download this installer script:

wget https://bootstrap.pypa.io/get-pip.py

Run it as root (or sudo it)

python3 get-pip.py

answered Feb 17, 2017 at 16:59

RobotJohnny's user avatar

RobotJohnnyRobotJohnny

9938 silver badges18 bronze badges

1

For CentOS 7 you would need to run this:

sudo yum install python34-setuptools
sudo easy_install-3.4 pip

Edit: You should then be able to install using pip3 install <package>

answered Feb 17, 2017 at 17:01

ProdIssue's user avatar

ProdIssueProdIssue

8271 gold badge7 silver badges20 bronze badges

2

Понравилась статья? Поделить с друзьями:
  • Module isapimodule notification executerequesthandler handler 1c web service extension error code 0x800700c1
  • Module initialization error http сервис
  • Module init error хроники риддика
  • Module build failed error enoent no such file or directory open
  • Module build failed error cannot find module node sass