1. 筹备装置环境

yum install gcc  zlib* openssl* -y 

2. linux 下 python 安装包的获取

官网下载地址:

https://www.python.org/downloads/


找到 本人想要的版本。

形式一:间接点击该链接下载,而后将安装包通过xftp 传送到近程服务器 的

/opt

门路下

形式二:

    1. 右键复制该链接:

      在 opt 门路下,应用wget命令下载:

      cd /optwget https://www.python.org/ftp/python/3.9.8/Python-3.9.8.tgz
    1. 如果零碎没有wget ,先下载 wget ,再反复上一步。

      yum -y install wget

3. 解压刚刚下载的安装包

tar -xzvf Python-3.9.8.tgz

并将解压后的文件夹更名 (非必要步骤)

mv Python-3.9.8 python398

将刚刚解压更名后的文件夹挪动到本人的想要的装置地位,并更名

mv python398 /usr/local

4. 进入该文件夹目录,编译装置

cd /usr/local/python398./configure --prefix=/usr/local/python398 --enable-optimizations

–prefix 参数是指定装置目录.

  • 编译:

    make
  • 编译胜利后,编译装置:

    make install

注:下面也能够组合一下

make && make install

短路写法只有编译胜利之后才会进行后边的编译装置,前边失败后边是不会执行的。

5. 查看是否装置胜利

查看python3.9的编译器:

cd /usr/local/python398/bin./python3.9

显示python 窗口即可。

6. 配置环境变量

vim /etc/profileexport PYTHON_HOME=/usr/local/python398export PATH=${PYTHON_HOME}/bin:$PATH

使得配置的环境变量立刻失效:

source /etc/profile

7. 配置软连贯

ln -s /usr/local/python398/bin/python3.9 /usr/bin/python39ln -s /usr/local/python398/bin/pip3.9 /usr/bin/pip39

报错状况:

问题1: Python装置报错 configure: error: in `/usr/local/python3/Python':

报错形容:

[root@localhost Python-3.5.4]# ./configure --prefix=/usr/local/python3.5

checking build system type... x86_64-pc-linux-gnu

checking host system type... x86_64-pc-linux-gnu

checking for python3.5... no

checking for python3... no

checking for python... python

checking for --enable-universalsdk... no

checking for --with-universal-archs... no

checking MACHDEP... linux

checking for --without-gcc... no

checking for --with-icc... no

checking for gcc... no

checking for cc... no

checking for cl.exe... no

configure: error: in `/usr/local/python3/Python-3.5.4':

configure: error: no acceptable C compiler found in $PATH

问题剖析:短少gcc编译环境

解决办法:

yum -y install gcc

问题2: 装置python时呈现Ignoring ensurepip failure:pip required SSL/TLS

报错形容:

Ignoring ensurepip failure: pip 9.0.1 requires SSL/TLS

问题剖析:短少openssl-devel包

解决办法:

yum -y install openssl-devel

问题3:如何设置环境变量,间接输出python3就能够进入python3版本

解决办法:

echo "export PATH=$PATH:/usr/local/python3/bin/" >> /etc/profile.d/python3.sh

export PATH=$PATH:/usr/local/python3/bin/

问题4:如果装了ipython,如何在python2,python3都能够应用ipyhon

解决办法:

先应用pip2 -V 和 pip3 -V 确认对应的python版本正确

之后

pip2 install ipython 装置python2的

pip3 install ipython 装置python3的

最初shell中执行ipython或ipython3会进入不同的python版本