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)
Similar Posts:
- NameError: name ‘pip’ is not defined
- Handling method of PIP error in pycharm installation
- Python.exe Error: No module named pip.__main__; ‘pip’ is a package and cannot be directly executed
- How to Solve ModuleNotFoundError: No module named ‘pip._internal’
- Error in installing Python 3.7 in CentOS 7.6 zipimport.ZipImportError : can’t decompress data; zlib not available
- AttributeError: module ‘pip’ has no attribute ‘main’
- Ubuntu18.04 (Python3.9) Error: ImportError: Cannot import name ‘sysconfig’ from ‘distutils’
- [Solved] pip and setuptools upgrade Error: Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-build-fH0Feg/pip/
- [Solved] Python Error: ModuleNotFoundError : No Module named ‘pip._internal’
- How to Solve Error: /usr/bin/env: ‘python’: No such file or directory