Python3.7源码安装

  • Centos7.X

# 如果使用 django   3.7版本需要安装 libffi-devel,之前版本不需要
yum install libffi-devel sqlite-devel -y 
curl -O https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar xf Python-3.7.0.tgz
cd Python-3.7.0
./configure
make && make install

  • Ubuntu

sudo apt-get install -y gcc g++ cmake make build-essential zlib1g-dev libbz2-dev libsqlite3-dev libssl-dev libxslt1-dev libffi-dev
wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz
tar -zxvf Python-3.9.9.tgz 
cd Python-3.9.9/
./configure --prefix=/usr/local/python3.9.9 --enable-loadable-sqlite-extensions --enable-shared
make && sudo make install

# 纯净环境
sudo ln -s /usr/local/python3.9.9/bin/python3 /usr/local/python3.9.9/bin/python3.9.9
sudo ln -s /usr/local/python3.9.9/bin/pip3 /usr/local/python3.9.9/bin/pip3.9.9
  • “--enable-shared”参数用于编译出libpython3.9m.so.1.0动态库

  • “--enable-loadable-sqlite-extensions”参数用于加载sqlite-devel依赖。

export LD_LIBRARY_PATH=/usr/local/python3.9.9/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/python3.9.9/bin:$PATH


# 或者把上面环境变量写入全局环境变量中

source ~/.bashrc

  • 其他系统版本安装

- 参考华为云: https://support.huaweicloud.com/cann503installguide/install_023.html

Last updated