0

After installing python3.6 and pipenv I tried to install requests with the command pip3 install requests and getting this error-

`Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'`

Here is how I installed python3.6

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install libssl-dev openssl libreadline-dev

$ cd ~

$ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

$ tar zxf Python-3.6.1.tgz

$ cd Python-3.6.1

$ ./configure

$ make

$ sudo make install

And here is how I installed pip env- pip3 install pipenv

After that i started getting that error. I have tried uninstalling python, python3, python-pip, python3-pip using below commands

$ sudo apt purge python

$ sudo apt purge python3

$ sudo apt purge python-pip

$ sudo apt purge python3-pip

Then installed them again using below commands $ sudo apt install python

$ sudo apt install python3

$ sudo apt install python-pip

$ sudo apt install python3-pip

But still getting that error. Also I always used sudo apt-get update before using those commands. After installing python3 again. When i check the version using the command python3 -V it shows python 3.6 How can I fix this problem?

1

First, check the location of the file:

$ which pip
path -> /usr/bin/pip

Then, open terminal and enter:

$ cd /usr/bin/    --> (path of pip)
$ sudo nano pip

In the file, you will see:

import sys
from pip import main
if __name__ == '__main__':
     sys.exit(main())

You must change to:

import sys
from pip import __main__
if __name__ == '__main__':
     sys.exit(__main__._main())

Save the changes and exit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.