Error after upgrading pip: cannot import name 'main'

Python

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

guru@guru-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'

guru@guru-notebook:~$ cat `which pip3`

#!/usr/bin/python3

# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because

# we didn't install the actual entry point from setup.py, don't use the

# pkg_resources API.

from pip import main

if __name__ == '__main__':

     sys.exit(main())

It was working fine earlier, I am not sure why it is throwing this error. I have searched about this error, but can't find anything to fix it.

Please let me know if you need any further detail, I will update my question.

1
Answers

Replies


You might have upgraded pip in your system using the pip install command. You should use a virtualenv instead of upgrading pip. Recover the pip3 binary by the following command,



sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall


 

 
 

If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.