0 votes
1 view
in Python by (47.8k points)

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

[email protected]:~$ 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'

[email protected]:~$ 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 Answer

0 votes
by (107k points)

The reason why you are getting import errors while trying to install any package using pip is that you must have upgraded your system accidentally.

To overcome this error you would not want to upgrade your system and instead use a virtualenv.

And if you want to use pip so you need to recover the pip3 for that you can use

sudo python3 -m pip uninstall pip 

After you uninstall the pip then reinstall it by the below-mentioned command:-

sudo apt install python3-pip --reinstall.

If You want to learn python for data science visit this python course by Intellipaat.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...