Error after upgrading pip cannot import name main

0 votes

Whenever I am trying to install any package using pip, I am getting this import error:

dey@niroj-notebook:~$ pip3 install numpy
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

dey@niroj-notebook:~$ cat `which pip3`

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':

It was working fine earlier, I am not sure why it is throwing this error.

How to fix this error?

Jun 5, 2020 in Python by kartik
• 37,490 points

1 answer to this question.

0 votes

Hello @kartik,

You must have inadvertently upgraded your system pip (probably through something like sudo pip install pip --upgrade)

pip 10.x adjusts where its internals are situated. The pip3 command you're seeing is one provided by your package maintainer and is not a file managed by pip.

You'll probably want to not upgrade your system pip and instead use a virtualenv.

To recover the pip3 binary you'll need to sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall.

If you want to continue in "unsupported territory" ,you can probably get away with python3 -m pip instead of pip3.

Hope it helps!

answered Jun 5, 2020 by Niroj
• 82,560 points

Related Questions In Python

0 votes
1 answer

ImportError: cannot import name 'main' in pip

Hi@akhtar, To avoid this error, you should upgrade ...READ MORE

answered Apr 15, 2020 in Python by MD
• 95,060 points
0 votes
1 answer
0 votes
1 answer

How to resolve ImportError: cannot import name 'add' in python ?

There's no module called "add" in random. ...READ MORE

answered Feb 12, 2019 in Python by Mark
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,850 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
0 votes
1 answer

Error: import No module name urllib2

Hii, You have to install the modules like bs4, ...READ MORE

answered May 5, 2020 in Python by Niroj
• 82,560 points