pip下载网站:https://bootstrap.pypa.io/
pip安装方式1:
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py //用哪个Python版本,安装的pip就关联哪个
// sudo python3.8 get-pip.py //关联3.8的版本
pip安装方式2:
sudo apt-get install python3-distutils
sudo apt-get install python3-pip //网上说安装Python模块时,需要指定具体的Python版本,但是python3.8-pip找不到,只有python3-pip
遇到的错误如下:
1.之前是各种参考网上的卸载Python3.8方法,把Ubuntu系统的图形化界面搞挂了,连终端都进不去,只好尽力挽救了
因为进不去终端,所以只能进命令行模式里重装python,直接用sudo apt-get install python3 是不行的
用下面的命令:
1)sudo apt install -f
2)sudo apt-get install python3-minimal
3)sudo apt-get -f install ubuntu-minimal ubuntu-standard ubuntu-desktop
参考:ubuntu卸载python后抢救方法
- 卸载Python3.8卸载不干净,导致下面错误
$ 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)
解:安装包可能出问题,将/var/lib/dpkg/info文件夹备份,并新建一个info文件夹,重新更新一下,再将更新后产生的文件,复制到备份中,再把名字改回来。
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
参考:ubuntu中误删/var/lib/dpkg/info的补救方法
- 再次执行后,但还是未解决Python3.8重新安装错误的问题。
$ 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.
解:觉得可能是没卸载干净,再次卸载并删除依赖,就能成功安装。
sudo apt-get remove --auto-remove python3.8 //卸载python3.8及其依赖
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’
解:
$ 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 (更换了源,并卸载重新安装sudo apt-get install python3-distutils)
一直怀疑是python3-distutils安装导致的错误。
之后pip所有版本都被关联成Python3.8,不过也是解决了我的问题。
$ pip3.8 -V
pip 22.0.3 from /home/tangzhiqiang/.local/lib/python3.8/site-packages/pip (python 3.8)
参考连接
https://blog.csdn.net/qq_27366789/article/details/80559074
https://www.jb51.net/article/221437.htm
https://blog.csdn.net/llm765800916/article/details/104576094
Ubuntu 系统下如何安装pip3工具