1.安装python3
root@hzf:~/.pip# apt install python3
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3 is already the newest version (3.10.6-1~22.04).
The following packages were automatically installed and are no longer required:
apport-symptoms bc distro-info eatmydata gir1.2-packagekitglib-1.0 libappstream4 libdw1 libeatmydata1 libglib2.0-bin libgstreamer1.0-0 libnetplan0 libpackagekit-glib2-18
libstemmer0d libyaml-0-2 packagekit packagekit-tools python-babel-localedata python3-attr python3-babel python3-blinker python3-certifi python3-cffi-backend
python3-chardet python3-constantly python3-cryptography python3-debconf python3-debian python3-distutils python3-hamcrest python3-httplib2 python3-hyperlink python3-idna
python3-incremental python3-jeepney python3-jinja2 python3-json-pointer python3-jsonpatch python3-jwt python3-keyring python3-lazr.uri python3-lib2to3 python3-magic
python3-markupsafe python3-netifaces python3-oauthlib python3-pexpect python3-pkg-resources python3-problem-report python3-ptyprocess python3-pyasn1 python3-pyasn1-modules
python3-pyparsing python3-pyrsistent python3-secretstorage python3-serial python3-service-identity python3-setuptools python3-systemd python3-tz python3-wadllib
python3-zope.interface
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@hzf:~/.pip# python3 --version
Python 3.10.12
root@hzf:~/.pip#
2.替换python3为默认
root@hzf:~/.pip# sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python (python) in auto mode
root@hzf:~/.pip#
3.安装python3-pip
sudo apt install python3-pip
root@hzf:~/.pip# sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
apport-symptoms bc distro-info eatmydata gir1.2-packagekitglib-1.0 libappstream4 libdw1 libeatmydata1 libglib2.0-bin libgstreamer1.0-0 libnetplan0 libpackagekit-glib2-18
libstemmer0d libyaml-0-2 packagekit packagekit-tools python-babel-localedata python3-attr python3-babel python3-blinker python3-certifi python3-chardet python3-constantly
python3-debconf python3-debian python3-hamcrest python3-httplib2 python3-hyperlink python3-idna python3-incremental python3-jinja2 python3-json-pointer python3-jsonpatch
python3-jwt python3-lazr.uri python3-magic python3-markupsafe python3-netifaces python3-oauthlib python3-pexpect python3-problem-report python3-ptyprocess python3-pyasn1
python3-pyasn1-modules python3-pyparsing python3-pyrsistent python3-serial python3-service-identity python3-systemd python3-tz python3-wadllib python3-zope.interface
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
python3-wheel python3-xdg
Recommended packages:
build-essential python3-dev python3-keyrings.alt
The following NEW packages will be installed:
python3-pip python3-wheel python3-xdg
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 182 kB of archives.
After this operation, 923 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu bionic-security/universe amd64 python3-pip all 9.0.1-2.3~ubuntu1.18.04.8 [114 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic-security/universe amd64 python3-wheel all 0.30.0-0.2ubuntu0.1 [36.7 kB]
Get:3 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 python3-xdg all 0.25-4ubuntu1.1 [31.3 kB]
Fetched 182 kB in 13s (14.4 kB/s)
Selecting previously unselected package python3-pip.
(Reading database ... 75952 files and directories currently installed.)
Preparing to unpack .../python3-pip_9.0.1-2.3~ubuntu1.18.04.8_all.deb ...
Unpacking python3-pip (9.0.1-2.3~ubuntu1.18.04.8) ...
Selecting previously unselected package python3-wheel.
Preparing to unpack .../python3-wheel_0.30.0-0.2ubuntu0.1_all.deb ...
Unpacking python3-wheel (0.30.0-0.2ubuntu0.1) ...
Selecting previously unselected package python3-xdg.
Preparing to unpack .../python3-xdg_0.25-4ubuntu1.1_all.deb ...
Unpacking python3-xdg (0.25-4ubuntu1.1) ...
Setting up python3-xdg (0.25-4ubuntu1.1) ...
Setting up python3-wheel (0.30.0-0.2ubuntu0.1) ...
Setting up python3-pip (9.0.1-2.3~ubuntu1.18.04.8) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
步骤一:下载get-pip.py脚本
首先,需要在Python官方网站上下载get-pip.py脚本。在浏览器中打开https://bootstrap.pypa.io/get-pip.py,并将其保存到本地。
步骤二:执行get-pip.py脚本
打开命令提示符或终端,并切换到get-pip.py所在的文件夹目录。使用以下命令执行get-pip.py脚本:
python get-pip.py