- 下载源文件
在官网选择安装包:https://www.python.org/downloads/
本人下载了Python-3.6.6.tgz - 解压安装文件切换目录
tar -xzf Python-3.6.6.tgz
cd Python-3.6.6
- 安装依赖包
yum -y install zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel gcc gcc-c++
- 编译安装(时间较长)
./configure --prefix=/opt/python3.6.6 --enable-shared && make && make install
- 设置环境变量
ln -s /opt/python3.6.6 /usr/local/python3
echo 'export PATH=$PATH:/usr/local/python3/bin/' >> ~/.bashrc
source ~/.bashrc
- 执行命令验证
python3 --version
【异常处理】
安装完成之后,验证python报错
python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
执行下面的命令之后,错误消失
echo '/usr/local/python3/lib/' >> /etc/ld.so.conf && ldconfig
python3 --version
返回 Python 3.6.6
网友评论