Skip to content

[Solved] pip Import Error: cannot import name main

Last Updated on 2021-06-07 by Clay


Problem

pip Import Error: cannot import name main

I had this error report once a while, it was happened when I upgrade my pip (A Python packages management tool). This is my bad habit, if I can not install a package smoothly, I always want to upgrade my software version.

Simply speaking, this problem usually occurs when the version upgrade.


Solved

First, we need to fix the "pip3" file.

sudo vim /usr/bin/pip3

And we will see the following code in the file:

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



But this is a old version, we have to edit it to:

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



Be careful! the suffix of "__main__._main()" is "_main()" not "main()"!

After we edit it, "Esc+wq" save the file, and use the following command to check it.

pip3 -V 

Output:

pip 19.3.1

If the command line print the version number, congratulations! we are done!

Tags:

Leave a ReplyCancel reply

Exit mobile version