ubuntu24编译安装python3.13
相关下载
Python: https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tgz
OpenSSL: https://openssl-library.org/source/old/index.html
这里说明一下,Python3.13使用的openSSL比较奇怪,只能使用OpenSSL1.1.1,使用最新的3.4也不行。至少在写这文章的时候是不行的
前置安装
apt update
apt install pkg-config libffi-dev libbz2-dev libncurses-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev libgdbm-compat-dev libdb-dev
安装OpenSSL
tar zxvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
./config --prefix=/usr/local/openssl1.1.1 shared
./config --prefix=/usr/local/openssl1.1.1 --openssldir=/usr/local/openssl1.1.1
make
make install
这里有个大坑,也是我排查很久的地方,就是上面的安装完之后,还要引入到配置里面的!
echo "/usr/local/openssl1.1.1/lib" >> /etc/ld.so.conf
安装Python3.13
tar zxvf Python-3.13.0.tgz
cd Python-3.13.0
./configure --prefix=/usr/local/python3.13 --with-openssl=/usr/local/openssl1.1.1 --enable-optimizations
make
make install
其它常用的python命令
# 创建venv环境
/usr/local/python3.13/bin/python3.13 -m venv venv
# 当前终端下激活venv
source venv/bin/activate
# 当前终端下退出venv
deactivate
# 创建项目依赖声明
/usr/local/python3.13/bin/pip freeze > requirements.txt
# 安装项目依赖
/usr/local/python3.13/bin/pip -r requirements.txt