Python and pip

pip download website: https://bootstrap.pypa.io/

pip installation method 1:

wget  https://bootstrap.pypa.io/get-pip.py

sudo python get-pip.py //Which Python version is used, the installed pip is associated with it

// sudo python3.8 get-pip.py //Associate version 3.8

pip installation method 2:

sudo apt-get install python3-distutils

sudo apt-get install python3-pip //It is said online that when installing a Python module, you need to specify a specific Python version, but python3.8-pip cannot be found, only python3-pip

The error encountered is as follows:

1. Before, I used various methods to uninstall Python 3.8 on the Internet, which caused the graphical interface of the Ubuntu system to hang up. I couldn’t even enter the terminal, so I had to try my best to save it.

Because I can't enter the terminal, I can only reinstall python in the command line mode. Directly using sudo apt-get install python3 will not work.

Use the following command:

1)sudo apt install -f

2)sudo apt-get install python3-minimal

3) sudo apt-get -f install ubuntu-minimal ubuntu-standard ubuntu-desktop

Reference: Rescue method after uninstalling python on ubuntu

  1. Uninstalling Python3.8 is not clean, resulting in the following error

$ sudo apt install python3.8
Reading package lists… Done
Building dependency tree
Reading state information… Done
Suggested packages:
python3.8-venv
The following NEW packages will be installed:
python3.8
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 0 B/433 kB of archives.
After this operation, 520 kB of additional disk space will be used.
Selecting previously unselected package python3.8.
(Reading database … 209664 files and directories currently installed.)
Preparing to unpack …/python3.8_3.8.12-1+bionic3_amd64.deb …
Unpacking python3.8 (3.8.12-1+bionic3) …
Setting up python3.8 (3.8.12-1+bionic3) …
/var/lib/dpkg/info/python3.8.postinst: 9: /var/lib/dpkg/info/python3.8.postinst: /usr/bin/python3.8: not found
dpkg: error processing package python3.8 (–configure):
installed python3.8 package post-installation script subprocess returned error exit status 127
Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) …
Processing triggers for mime-support (3.60ubuntu1) …
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …
Errors were encountered while processing:
python3.8
E: Sub-process /usr/bin/dpkg returned an error code (1)

Solution: There may be a problem with the installation package. Back up the /var/lib/dpkg/info folder, create a new info folder, update it again, then copy the updated files to the backup, and then change the name back. .

sudo mv /var/lib/dpkg/info  /var/lib/dpkg/info_back

sudo mkdir /var/lib/dpkg/info

sudo apt-get update

sudo apt-get -f install

sudo mv /var/lib/dpkg/info/*  /var/lib/dpkg/info_back

sudo rm -rf /var/lib/dpkg/info/

sudo mv /var/lib/dpkg/info_back  /var/lib/dpkg/info

Reference: Remedy for accidentally deleting /var/lib/dpkg/info in ubuntu

  1. After executing it again, the problem of Python3.8 reinstallation error was still not solved.

$ sudo apt-get install python3.8

Reading package lists… Done
Building dependency tree
Reading state information… Done
python3.8 is already the newest version (3.8.12-1+bionic3).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

Solution: I think it may not be completely uninstalled. Uninstall again and delete the dependencies, and the installation will be successful.

sudo apt-get remove --auto-remove python3.8 //Uninstall python3.8 and its dependencies

4.

$ sudo python3.8 get-pip.py
[sudo] password for tangzhiqiang:
Sorry, try again.
[sudo] password for tangzhiqiang:
/home/tangzhiqiang/.local/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
Collecting pip
Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
Installing collected packages: pip
/home/tangzhiqiang/.local/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
/home/tangzhiqiang/.local/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
Successfully installed pip-21.3.1
WARNING: Running pip as the ‘root’ user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

$ pip3 -V
Traceback (most recent call last):
File “/usr/bin/pip3”, line 5, in
from pip._internal.cli.main import main
ModuleNotFoundError: No module named ‘pip’

untie:

$ sudo apt-get install python3-pip
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
python3-pip
0 upgraded, 1 newly installed, 0 to remove and 51 not upgraded.
Need to get 114 kB of archives.
After this operation, 601 kB of additional disk space will be used.
Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/universe amd64 python3-pip all 9.0.1-2.3~ubuntu1.18.04.5 [114 kB]
Fetched 114 kB in 0s (1,589 kB/s)
Selecting previously unselected package python3-pip.
(Reading database … 209800 files and directories currently installed.)
Preparing to unpack …/python3-pip_9.0.1-2.3~ubuntu1.18.04.5_all.deb …
Unpacking python3-pip (9.0.1-2.3~ubuntu1.18.04.5) …
Setting up python3-pip (9.0.1-2.3~ubuntu1.18.04.5) …
/usr/lib/python3.8/subprocess.py:842: RuntimeWarning: line buffering (buffering=1) isn’t supported in binary mode, the default buffer size will be used
self.stdin = io.open(p2cwrite, ‘wb’, bufsize)
Processing triggers for man-db (2.8.3-2ubuntu0.1) …

https://blog.csdn.net/llm765800916/article/details/104576094 (Changed the source, uninstalled and reinstalled sudo apt-get install python3-distutils)

I have always suspected that the error was caused by the installation of python3-distutils.

After that, all versions of pip were associated with Python3.8, which also solved my problem.

$ pip3.8 -V
pip 22.0.3 from /home/tangzhiqiang/.local/lib/python3.8/site-packages/pip (python 3.8)

Reference connection

https://blog.csdn.net/qq_27366789/article/details/80559074

https://www.jb51.net/article/221437.htm

https://blog.csdn.net/llm765800916/article/details/104576094

How to install the pip3 tool under Ubuntu system

Guess you like

Origin blog.csdn.net/Ternence_zq/article/details/128363157