In Ubuntu, after upgrading PIP3, there is an error of importerror: cannot import name ‘main’ when using PIP3. This article describes how to correct this error, pro test effective
Install python3:
sudo apt install python3
Install PIP3:
sudo apt install python3-pip
Upgrade PIP3:
python3 -m pip install –upgrade pip
Then when using PIP3 to install other modules, the error of importerror: cannot import name ‘main’ appears
The fix is to modify the file/usr/bin/PIP3
Here is the original content of this document:
from pip import main
if __name__ == '__main__':
sys.exit(main())
Obviously, the main function was modified after PIP3 upgrade
Now modify this file as follows:
from pip import __main__ //must modify
if __name__ == '__main__':
sys.exit(__main__._main())//add __main__._
After saving, and then using PIP3, everything is normal
~$ pip3 –version
pip 19.0.3 from /home/xinlin/.local/lib/python3.6/site-packages/pip (python 3.6)
I don’t know why, when installing python3, the version of the built-in PIP3 is so low. If you change it to a higher version, many people won’t face this problem
another method is to reconstruct the symbolic connection of/usr/bin/PIP3
Using python3 – M pip or python3 – M site — user base, you can see where PIP3 is installed and rebuild the symbolic connection (How to create symbolic links)