close

[Solved] Error after upgrading pip: cannot import name ‘main’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Error after upgrading pip: cannot import name ‘main’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Error after upgrading pip: cannot import name ‘main’ Error Occurs?

Today I get the following error Error after upgrading pip: cannot import name ‘main’ in python.

How To Solve Error after upgrading pip: cannot import name ‘main’ Error ?

  1. How To Solve Error after upgrading pip: cannot import name 'main' Error ?

    To Solve Error after upgrading pip: cannot import name 'main' Error You must have inadvertently upgraded your system pip (probably through something like sudo pip install pip --upgrade)

  2. Error after upgrading pip: cannot import name 'main'

    To Solve Error after upgrading pip: cannot import name 'main' Error You must have inadvertently upgraded your system pip (probably through something like sudo pip install pip --upgrade)

Solution 1

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 (presumably debian based here?) and is not a file managed by pip.

You can read more about this on pip’s issue tracker

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” (upgrading a system package outside of the system package manager), you can probably get away with python3 -m pip ... instead of pip3.

Solution 2


We can clear the error by modifying the pip file.

Check the location of the file:

$ which pip

path -> /usr/bin/pip

Go to that location(/usr/bin/pip) and open terminal

Enter: $ sudo nano pip

You can see:

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

Change to:

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

then ctrl + o write the changes and exit

Hope this will do!!

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read