话不多说,在Linux上完成Python从源码编译安装全流程

话不多说,直接上代码:

# 安装工具链,如果已装完请跳过
sudo apt-get install -y gcc g++ make cmake zlib1g zlib1g-dev libbz2-dev libsqlite3-dev libssl-dev libxslt1-dev libffi-dev unzip pciutils net-tools libncursesw5-dev

# 把需要安装的版本号在这里改,后面会联动改动,当然前提是ftp上有
VERSION=3.8.9

# 清除上次下载和安装的目录
sudo rm Python-$VERSION.tgz
sudo rm -rf Python-$VERSION
sudo rm -rf /usr/local/python$VERSION

# 下载解压配置编译安装一套连招
wget https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tgz
tar -zxvf Python-$VERSION.tgz
cd Python-$VERSION
./configure --prefix=/usr/local/python$VERSION --enable-loadable-sqlite-extensions --enable-shared
make -j 4
sudo make install -j 4

# 添加到环境变量,并且注释也加上了
echo "" >> ~/.bashrc
echo "# Add python$VERSION to PATH" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/python$VERSION/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc
echo "export PATH=/usr/local/python$VERSION/bin:\$PATH" >> ~/.bashrc

# 这一行需要手动运行,或者重启终端也行
source ~/.bashrc

然后就可以运行了:

话不多说,在Linux上完成Python从源码编译安装全流程_第1张图片

你可能感兴趣的:(Python,Linux,linux,python)