https://www.python.org/downloads/source/
安装python3
[root@localhost ~]# yum groupinstall "Development Tools" -y
[root@localhost ~]# yum -y install zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel libffi-devel
[root@localhost ~]# wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
[root@localhost ~]# tar -xvf Python-3.8.3.tar.xz -C /usr/local/
[root@localhost ~]# cd /usr/local/Python-3.8.3/
修改配置信息
使用vim去掉如下注释
[root@localhost Python-3.8.3]# vim Modules/Setup
readline readline.c -lreadline -ltermcap
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
也可使用
sed -ri 's/^#readline/readline/' Modules/Setup
sed -ri 's/^#(SSL=)/\1/' Modules/Setup
sed -ri 's/^#(_ssl)/\1/' Modules/Setup
sed -ri 's/^#([\t]*-DUSE)/\1/' Modules/Setup
sed -ri 's/^#([\t]*-L\$\(SSL\))/\1/' Modules/Setup
开始编译安装
[root@localhost Python-3.8.3]# ./configure --enable-shared
[root@localhost Python-3.8.3]# make && make install
--enable-shared 指定安装共享库,共享库在使用其他需调用python的软件时会用到,比如使用mod_wgsi 连接Apache与python时需要。
配置环境
[root@localhost Python-3.8.3]# echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib" >/etc/profile.d/python3_lib.sh
[root@localhost Python-3.8.3]# echo "/usr/local/lib" > /etc/ld.so.conf.d/python3.conf
[root@localhost Python-3.8.3]# python3 --version
Python 3.8.3
[root@localhost Python-3.8.3]# python3
Python 3.8.3 (default, May 23 2020, 20:23:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost Python-3.8.3]# pip3 -V
pip 19.2.3 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
输出的信息中的目录 /usr/local/lib/python3.8/site-packages 用于存放安装的第三方模块
配置使用本地的源安装第三方模块
[root@localhost Python-3.8.3]# cd
[root@localhost ~]# mkdir .pip
[root@localhost ~]# echo '[global]' >> .pip/pip.conf
[root@localhost ~]# echo 'index-url=https://mirrors.aliyun.com/pypi/simple' >> .pip/pip.conf
安装ipython测试
[root@localhost ~]# pip3 install ipython
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting ipython
...
...
[root@localhost ~]# ipython
Python 3.8.3 (default, May 23 2020, 20:23:19)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.14.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: