First, what is the pip
pip is a Python package management tool that provides a Python package to find, download, install, uninstall function.
Second, the upgrade version pip
1, the default Ubuntu comes pip (pip 9.0.1) is based on the version of Python2.7
2, we need to re-install based pip Python3 of:
sudo apt-get install python3-pip
3, upgrade pip3 version:
python3 -m pip install --upgrade pip
4, see the pip version Python3, if reported the following error:
ImportError: cannot import name main
Workaround: Edit usr / bin / pip3 file
before fixing:
from pip import main
if __name__ == '__main__':
sys.exit(main())
Modified:
from pip import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
Verify the repair has been successfully entered into force: pip3 -V
Terminal printing:
pip 19.3.1 from /home/wenbin/.local/lib/python3.6/site-packages/pip (python 3.6)
5, a key upgrade all Python packages
Write a Python script that can be executed, the following is the code:
import pkg_resources
from subprocess import call
for packages in [dist.project_name for dist in pkg_resources.working_set]:
call("pip3 install --upgrade " + ''.join(packages) + ' --user', shell=True)
Because my Python3 corresponding pip is pip3, so the script here call ( "pip3 install --upgrade" + '' .join (packages) + '--user', shell = True) in the pip to be written pip3
Then in view the history of Python version of the package as well as those who:
pip3 list --outdated
Terminal printing:
Package Version Latest Type
----------- ------- ------ -----
distro-info 0.0.0 0.10 sdist
pycairo 1.16.2 1.18.1 sdist
pycups 1.9.73 1.9.74 sdist
pygobject 3.26.1 3.34.0 sdist
Then use those who can not upgrade packages
pip3 install --upgrade to be upgraded package name
命令进行逐个升级即可,我看那四个包我也不经常用,我都懒得去升级了。。。(PS:刚装好的Ubuntu 18.04,截图不方便,先凑活着看吧-.-)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
至此...完结...