Ubuntu 18.04 one-click upgrade of all third-party Python packages and installation of Python packages

Ubuntu 18.04 one-click upgrade of all third-party Python packages and installation of Python packages

1. What is pip

pip is a Python package management tool that provides the functions of searching, downloading, installing, and uninstalling Python packages.

2. Upgrade pip version

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

2. We need to reinstall pip based on Python3:

sudo apt-get install python3-pip

3. Upgrade 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 main
if __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

The terminal prints:

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

5. Upgrade all Python packages with one click

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

Next, let's check what other packages there are in the historical versions of Python:

pip3 list --outdated

The terminal prints:

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 these non-upgraded packages

pip3 install --upgrade 要升級的包名

You can run the command to upgrade them one by one. I don’t use those four packages often, so I’m too lazy to upgrade them. . . (PS: I just installed Ubuntu 18.04, so it’s not convenient to take screenshots. Let’s just watch it for now-.-)

Knowledge point extension: Ubuntu 18.04 installs Python package

Recently, I have been running two models at the same time, and the cloud server can't handle it.

I got a company windows host, changed it to ubuntu18.04 and gave it to me to use mbp remote ssh. Cool~

1. Configure ssh-server

2. Install Python, etc.

Unbuntu18.04 comes with python3.6.8

1. Install pip3 and execute

sudo apt install python3-pipi

2. Install vim and execute

sudo apt install vim

2. Configure the image first and then install each python package

pip3 install some-package

Torch actually shows that it takes 20 hours to download, so I still use Tsinghua pypi mirror 8~

Note that an error may occur 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.

Just add --user after install:

pip3 install -user some-package

Summarize

The above is the method of upgrading all third-party Python packages and installing Python packages in Ubuntu 18.04 with one click. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Quickly generate Python crawler request header with one click
  • Use Python to create a data preprocessing tool (multiple operations can be completed with one click)
  • How to package Python Web projects to achieve one-click startup without installation
  • Use Python code to achieve one-click background removal function
  • How to install all dependent packages in Python with one click
  • Python one-click search for unused images, audio, and video resources in iOS projects
  • Python method to get Baidu network disk extraction code in one click
  • Python one-click method to create WeChat friends picture wall
  • Python dictionary loop to add a key multiple values ​​usage example
  • Python Fun Crawler Use Python to implement one-click teaching evaluation in smart campus

<<:  MySQL 8.0.15 installation and configuration tutorial under Win10

>>:  Detailed explanation of JavaScript WebAPI, DOM, events and operation element examples

Recommend

Implementation of importing and exporting vue-element-admin projects

vue-element-admin import component encapsulation ...

Perfect solution to MySQL common insufficient memory startup failure

1. If MySQL is not started successfully, check th...

How to modify the port mapping of a running Docker container

Preface When docker run creates and runs a contai...

Web design reference firefox default style

Although W3C has established some standards for HT...

Bootstrap realizes the effect of carousel

This article shares the specific code of Bootstra...

Analysis of the use and principle of Docker Swarm cluster management

Swarm Cluster Management Introduction Docker Swar...

Application of mapState idea in vuex

Table of contents 1. Map method 2. Application ba...

Detailed explanation of the platform bus of Linux driver

Table of contents 1. Introduction to platform bus...

js to implement verification code interference (dynamic)

This article example shares the specific code of ...

Essential bonus items for optimizing and packaging the front end of Vue projects

Table of contents Preface 1. Routing lazy loading...

JS realizes the card dealing animation

This article example shares the specific code of ...

What you need to know about filters in Vue

Table of contents Preface What is a filter How to...

Detailed explanation of .bash_profile file in Linux system

Table of contents 1. Environment variable $PATH: ...

Detailed tutorial on installing MySQL 8.0 from source code on CentOS 7.4

Table of contents 1. Environment 2. Preparation 3...