Skip to content
  1. 下载 Python3

https://www.python.org/downloads/ 下载对应的 Python3 版本。下载地址:https://www.python.org/ftp/python/

shell
mkdir /usr/local/python3 
tar -zxvf Python-3.10.13.tgz 
cd Python-3.10.13
ls
./install-sh 
cat install-sh

Debian 安装系统库

shell
sudo apt install net-tools
sudo apt install vim wget curl git
sudo apt install gcc make build-essential 
sudo apt install -y libssl-dev zlib1g-dev
sudo apt install -y libbz2-dev libreadline-dev libsqlite3-dev llvm
sudo apt install -y libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-dev 
sudo apt install -y tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev libc6-dev
  1. CentOS 安装系统库

安装编译必要库。

shell
yum -y groupinstall "Development tools"
yum install -y ncurses-devel gdbm-devel xz-devel sqlite-devel tk-devel uuid-devel readline-devel bzip2-devel libffi-devel
yum install -y openssl-devel openssl11 openssl11-devel
yum install -y libffi-devel zlib1g-dev
export CFLAGS=$(pkg-config --cflags openssl11)
export LDFLAGS=$(pkg-config --libs openssl11)
echo $CFLAGS
echo $LDFLAGS
./configure --prefix=/usr/local/python3 --with-ssl --enable-optimizations
make -j4
make install

其他:

shell
mkdir build
cd build
../configure --prefix=/usr/local/python3 --with-ssl-default-suites=openssl --enable-optimizations
make -j4
make install

# 创建软连接
sudo ln -s /usr/local/python3/bin/python3.10 ./python
sudo ln -s /usr/local/python3/bin/python3.10 ./python3
sudo ln -s /usr/local/python3/bin/python3.10 ./python3.10
sudo ln -s /usr/local/python3/bin/python3.10-config python-config
sudo ln -s /usr/local/python3/bin/python3.10-config python3-config
sudo ln -s /usr/local/python3/bin/python3.10-config python3.10-config
sudo ln -s /usr/local/python3/bin/pip3.10 ./pip
sudo ln -s /usr/local/python3/bin/pip3.10 ./pip3
sudo ln -s /usr/local/python3/bin/pip3.10 ./pip3.10
  1. 修改 PIP 源为国内
shell
mkdir -p ~/.pip
touch ~/.pip/pip.conf
vim ~/.pip/pip.conf

内容为:

ini
[global]
timeout = 60000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
disable-pip-version-check = true
user-base = /Volumes/Software/Applications/anaconda3
user-site = /Volumes/Software/Applications/anaconda3/lib/python3.8/site-packages
[install]
use-mirrors = true
mirrors = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
  1. 调整 Python PATH路径

删除 /usr/bin/python 采用软连接或修改为 python2. 将 python3 采用软连接到 /usr/local/bin。以及 pip