Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Ubuntu18.04 one-click upgrade of all the third-party packages of Python and the method of installing python packages

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

What is pip

Pip is a Python package management tool, which provides the functions of finding, downloading, installing and uninstalling Python packages.

II. Upgrade the pip version

1. The default pip that comes with Ubuntu (pip 9.0.1) is based on Python2.7.

2. We need to reinstall the Python3-based pip:

Sudo apt-get install python3-pip

3. Upgrade the pip3 version:

Python3-m pip install-- upgrade pip

4. Check the pip version of Python3. If the following error is reported:

ImportError: cannot import name main

Solution: 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 ())

Verify that the fix has taken effect successfully: pip3-V

Terminal printing:

Pip 19.3.1 from / home/wenbin/.local/lib/python3.6/site-packages/pip (python3.6)

5. Upgrade all Python packages with one click

Just write a Python script to execute. Here's 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 my Python3 is pip3, the pip in the script call ("pip3 install-- upgrade" + '.join (packages) +'-- user', shell=True) is written as pip3.

Next, take a look at the historical version of Python and those packages:

Pip3 list-outdated

Terminal printing:

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 these unupgraded packages

Pip3 install-- the name of the package to be upgraded by upgrade

Order to upgrade one by one. I don't think I often use those four bags. I don't even bother to upgrade. (PS: just installed Ubuntu 18.04. it's not convenient to take screenshots. Let's watch it alive first.)

Knowledge extension: ubuntu 18.04 install python package

Recently, running two models at the same time, the cloud server can no longer bear it.

Set up a mainframe of the company windows, wash it into ubuntu18.04 and give it to me for mbp remote ssh. Cool ~

1. Configure ssh-server

two。 Install python, etc.

Unbuntu18.04 comes with python3.6.8

1. Install pip3, execute

Sudo apt install python3-pipi

two。 Install vim, execute

Sudo apt install vim

two。 Configure the image before installing each python package

Pip3 install some-package

Torch unexpectedly shows that it will take 20 hours to download, or use Tsinghua pypi mirror image 8 ~

Note that an error may be reported after upgrading pip10

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] insufficient permissions:'/ usr/local/lib/python3.6/dist-packages/defusedxml-0.6.0.dist-info'

Consider using the `--user` option or check the permissions.

Add-- user after install:

Pip3 install-user some-package

Summary

The above is introduced to you by the editor of Ubuntu18.04 one-click upgrade of all third-party packages of Python and the method of installing python packages. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report