linux源码编译安装Python3.9.6及pip
linux源码编译安装Python3.9.6及pip
-
卸载之前的python
sudo apt remove python3 sudo apt autoremove
-
安装依赖
sudo apt update sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
-
下载源码包
cd /opt sudo wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz tar -xzvf Python-3.9.6.tgz
-
编译安装
cd Python3.9.6/ ./configure --prefix=/usr/local/python3 # pip3使用ssl #编译 make #安装 sudo make install
-
设置python新路径
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
-
安装pip
sudo apt-get install python-pip
-
设置pip路径
ln -s /usr/local/bin/pip /usr/bin/pip
-
查看版本
python --version
###Python 3.9.6
pip --verion
###pip 21.1.3 from /usr/local/python3/lib/python3.9/site-packages/pip (python 3.9)
9.设置环境变量
在家目录创建(.bash_profile): vim ~/.bash_profile
#配置python
export PYTHON_HOME=/usr/local/python3
export PATH=$PYTHON_HOME/bin:$PATH
执行source ~/.bash_profile命令使配置生效