参考教程:
参考教程:编译安装Python3.7.5
由于网站有可能会变化,所以给出访问路径,如果链接点不进去可以按照层级目录找一下:
昇腾社区 > 文档首页 > CANN社区版 > 环境准备 > 软件安装 (命令行) > 常用操作 > 编译安装Python3.7.5
话不多说,直接上代码:
# 安装工具链,如果已装完请跳过
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
# 这里写自己需要的Python版本号,后面的链接和目录会联动改动,当然前提是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