Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to upgrade the Python Library in Ubuntu18.04

Shulou Source: shulou.com Published: 2022-06-01 23:45:10 11月13日 Update

How to upgrade Python libraries in Ubuntu 18.04? I believe that many inexperienced people are helpless about this. For this reason, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Python is mainly used for: 1. Web development;2. Data science research;3. Web crawler;4. Embedded application development;5. Game development;6. Desktop application development.

Upgrade pip version

The default pip that comes with Ubuntu (pip 9.0.1) is based on Python 2.7.

We need to reinstall Python 3 based pip:

sudo apt-get install python3-pip

= Upgrade pip3 version:

python3 -m pip install --upgrade pip

Check the pip version of Python 3 and see if the following error is reported:

ImportError: cannot import name main

Workaround: Edit the usr/bin/pip3 file

Before modification:

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

After modification:

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

Verification modification successfully takes effect: pip3 -V

Terminal Print:

pip 19.3.1 from /home/work/.local/lib/python3.6/site-packages/pip (python 3.6)

Next, upgrade all Python packages with one click

Write a Python script to execute, here is the code:

import pkg_resourcesfrom 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 the pip corresponding to Python3 is pip3, the pip in call("pip3 install --upgrade "+''.join(packages)+'--user', shell=True) should be written as pip3 in the script

Next, check out Python's historical versions of the package and those:

pip3 list --outdated

Terminal Print:

Package Version Latest Type----------- ------- ------ -----distro-info 0.0.0 0.10 sdistpycairo 1.16.2 1.18.1 sdistpycups 1.9.73 1.9.74 sdistpygobject 3.26.1 3.34.0 sdist

And then use it on these unupgraded packages

pip3 install --upgrade Package name to upgrade Having read this, do you know how to upgrade Python libraries in Ubuntu 18.04? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Tags: Upgrade version development application next content application development method more terminal script problem success helpless for this code method history reason for this Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno vpn Linux Shulou Technology Huawei