刚到手的Centos
服务器默认的Python
版本是2.7
,现在很多新开发的Python
均需要3.X
以上。下面升级Centos
的预装Python
版本到最新。
下载Python3.9.5 1 2 wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz tar zxvf Python-3.9.5.tgz
安装必须的包 1 dnf -y install gcc libffi-devel
安装 1 2 3 4 cd Python-3.9.5/mkdir /usr/local /python3/ ./configure --prefix=/usr/local /python3 --enable-optimizations make && make install
替换原先的 Python3 和 pip3 1 2 3 4 mv /usr/bin/python3 /usr/bin/python.bak mv /usr/bin/pip3 /usr/bin/pip.bak ln -s /usr/local /python3/bin/python3 /usr/bin/python3 ln -s /usr/local /python3/bin/pip3 /usr/bin/pip3
添加环境变量 1 2 echo "export PATH=/usr/local/python3/bin:$PATH " >>/root/.bashrcsource /root/.bashrc
执行python3进行测试 1 2 3 4 5 python3 Python 3.9.5 (default, Oct 15 2021, 16:44:21) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)] on linux Type "help" , "copyright" , "credits" or "license" for more information. >>>
now, 可以开心的玩蛇了~
Done.