查看系统默认python
执行路径
[root@iZhp ~]# which python
/usr/bin/python
查看默认python配置和连接等
进入执行路径 cd /usr/bin/
[root@iZhp bin]# ll python*
lrwxrwxrwx 1 root root 7 Jul 11 2019 python -> python2
lrwxrwxrwx 1 root root 9 Jul 11 2019 python2 -> python2.7
-rwxr-xr-x 1 root root 7216 Jun 21 2019 python2.7
-rwxr-xr-x 1 root root 1835 Jun 21 2019 python2.7-config
lrwxrwxrwx 1 root root 16 Jul 11 2019 python2-config -> python2.7-config
lrwxrwxrwx 1 root root 14 Jul 11 2019 python-config -> python2-config
[root@iZ bin]#
使用了多层软链接进行指向python2版本的执行路径
安装python3依赖包,源码安装使用
# 安装依赖库
yum -y install gcc* glien*
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install libffi libffi-devel
python3 安装
- 下载文件 wget方式,源码安装
切换到、usr/local/目录下,将文件下载到该目录下
[root@iZh bin]# cd /usr/local/
[root@iZhp local]# ls
aegis bin etc games include lib lib64 libexec sbin share src
[root@iZhp local]# wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz
--2020-07-01 15:15:57-- https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz
Resolving www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:1a::223
Connecting to www.python.org (www.python.org)|151.101.228.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17828408 (17M) [application/octet-stream]
Saving to: ‘Python-3.8.1.tar.xz’
1% [=> ] 298,631 10.5KB/s eta 23m 52s
- 解压
tar -xvJf Python-3.6.2.tar.xz
[root@iZ local]# ls
aegis bin etc games include lib lib64 libexec Python-3.8.1 Python-3.8.1.tar.xz sbin share src
- 配置: 指定安装路径
[root@iZhp local]# cd Python-3.8.1
[root@iZhp Python-3.8.1]# ./configure preifx=/usr/local/python3
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
- 编译安装
[root@iZhp Python-3.8.1]#
[root@iZhp Python-3.8.1]# make && make install
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -I./Include/internal -I. -
........
Looking in links: /tmp/tmpp_opep1t
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.2.3 setuptools-41.2.0
- 创建链接: 同时创建python3 和pip3 的软连接
pip3 安装路径在python3 安装路径下,3.8会按照在/usr/local/bin 中
ln -s /usr/local/python3/bin/python3 /usr/bin/python