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?


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__':

You must change to:

import sys
from pip import __main__
if __name__ == '__main__':

Save the changes and exit

| improve this answer | |
  • This after hours and hours of trying finally solved my problem, thank you! – unicornication Aug 7 '19 at 8:03
  • This was the answer to my problem too, none of the weird hash commands and stuff like the other threads suggest... – Leftover Salad Dec 5 '19 at 21:54

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.