Linux编译安装Python3.6.8


Linux编译安装Python3.6.8

一、下载源码包

官网链接:https://www.python.org/downloads/source/

下载gzipped source tarball

二、依赖安装

yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel

三、编译安装

tar -zxvf Python-3.6.8.tgz

cd Python-3.6.8/

./configure --prefix=/data/python-3.6.8 --with-openssl=/usr/local/openssl

make

make install

四、添加到环境变量

方式一:

vim /etc/profile.d/custom.sh

export PATH=/data/python-3.6.8/bin:$PATH

csh版:

vim /etc/profile.d/custom.csh

setenv PATH /data/python-3.6.8/bin:$PATH

方式二:

ln -s /data/python-3.6.8/bin/python3.6 /usr/bin/python3  #添加python3的软链接 
ln -s /data/python-3.6.8/bin/pip3.6 /usr/bin/pip3        #添加 pip3 的软链接 
ln -s /data/python-3.6.8/bin/pip3.6 /usr/bin/pip         #添加 pip 的软链接 
  • 如果提示

    ln: failed to create symbolic link ‘/usr/bin/python3’: File exists
    ln: failed to create symbolic link ‘/usr/bin/pip3’: File exists
    
    • 删除原有软链接

      rm -rf /usr/bin/python3
      ln -s /data/python-3.6.8/bin/python3.6 /usr/bin/python3
      rm -rf /usr/bin/pip3
      ln -s /data/python-3.6.8/bin/pip3.6 /usr/bin/pip3
      ln -s /data/python-3.6.8/bin/pip3.6 /usr/bin/pip