Linux 通过源码编译安装 Python3.8.12 开启编译动态链接库
ubuntu
$ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
Fedora/CentOS
$ sudo yum install @development zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel findutils
$ sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
检查安装的包是否有更新
yum check-upgrade
更新开发包可使用
$ yum -y upgrade freetype-devel glibc-devel kernel-devel keyutils-libs-devel krb5-devel libX11-devel libXau-devel libcom_err-devel libffi-devel libstdc++-devel libselinux-devel libsepol-devel libuuid-devel libxcrypt-devel ncurses-devel openssl-devel pcre2-devel sqlite-devel zlib-devel expat-devel fontconfig-devel
安装wget
yum -y install wget
linux 其他方法安装 wget : rpm -ivh wget-1.14-15.el7_4.1.x86_64.rpm (https://pkgs.org/download/wget)
在 /usr/local/ 目录下
wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tgz
解压
tar -xvzf Python-3.8.12.tgz
重命名目录
mv Python-3.8.12 python3.8
$ ./configure --prefix=/usr/local/python3.8 --enable-optimizations --enable-shared
执行完后继续编译、测试
$ make
执行完后继续安装
$ make install
添加软连接
$ ln -s /usr/local/python3.8/python /usr/local/bin/python3.8
$ ln -s /usr/local/python3.8/libpython3.8.so.1.0 /usr/lib64/libpython3.8.so.1.0
$ ln -s /usr/local/python3.8/libpython3.8.so /usr/lib64/libpython3.8.so
查看python所在目录
whereis python
python3.8 -V
Python 3.8.12
ubuntu 安装pip3
# sudo apt update
# sudo apt install python3-pip
其他方式安装pip : Installation - pip documentation v23.1.2 (pypa.io)
设置pip 镜像源
root@localserver:/# pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
Writing to /root/.config/pip/pip.conf
root@localserver:/# cat /root/.config/pip/pip.conf
[global]
timeout = 6000
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com