apt-get update apt-get install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz
root@062e241f5835:/# wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz
–2021-05-02 08:49:19-- https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz
Resolving www.python.org (www.python.org)… 151.101.108.223, 2a04:4e42:1a::223
Connecting to www.python.org (www.python.org)|151.101.108.223|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 25411523 (24M) [application/octet-stream]
Saving to: ‘Python-3.9.4.tgz’
Python-3.9.4.tgz 100%[===================>] 24.23M 720KB/s in 39s
2021-05-02 08:49:59 (631 KB/s) - ‘Python-3.9.4.tgz’ saved [25411523/25411523]
解压源码包:
tar -zxvf Python-3.9.4.tgz
进入解压后的目录:
cd Python-3.9.4
./configure --prefix=/usr/local ./configure --enable-optimizations
这里的–prefix=/usr/local用于指定安装目录(建议指定)。如果不指定,就会使用默认的安装目录。
–enable-optimizations选项通过运行多个测试来优化Python二进制文件。 这会使构建过程变慢。
启动Python 3.9.4构建过程:
make -j 8
构建过程完成后,输入以下命令安装Python二进制文件:
sudo make altinstall
不要使用标准的make install,因为它将覆盖默认的系统python3二进制文件。
查看安装完成版本:
python3.9 --version
apt-get install python3-pip
升级pip3 (目前最新pip21.1.1)
pip3 install --upgrade pip
root@062e241f5835:/Python-3.9.4# pip3 install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/cd/6f/43037c7bcc8bd8ba7c9074256b1a11596daa15555808ec748048c1507f08/pip-21.1.1-py3-none-any.whl (1.5MB)
100% |################################| 1.6MB 489kB/s
Installing collected packages: pip
Found existing installation: pip 9.0.1
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-21.1.1
root@062e241f5835:/Python-3.9.4#
pip3 -V