CentOS 源码安装 Python3

CentOS 源码安装 Python3

源码安装 Python3.6 步骤

下载源码并编译

使用编译安装,首先安装编译依赖

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

创建一个工作目录,并进入目录

mkdir -p /usr/local/workspace/py36 && cd /usr/local/workspace/py36

获取 Python3.6 源码包

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

解压

tar -zxf Python-3.6.0.tgz

进入源码目录

cd Python-3.6.0

指定程序安装目录

./configure prefix=/usr/local/python3.6

编译

make && make install

安装已经完成

创建软链接

为了方便使用,创建软链接

ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python3.6
ln -s /usr/local/python3.6/bin/pip3.6 /usr/bin/pip3.6

执行 python3.6 测试

$ python3.6
Python 3.6.0 (default, Aug 18 2020, 12:41:53) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

替换默认的 Python2

删除默认软链接

rm -f /usr/bin/pip
rm -f /usr/bin/python

创建 Python3.6 的软链接

ln -s /usr/bin/python3.6 /usr/bin/python
ln -s /usr/bin/pip3.6 /usr/bin/pip

此时,执行 python 将默认执行 Python3.6

posted @ 2020-08-18 14:54  吴思老  阅读(134)  评论(0编辑  收藏  举报