Linux安装
tips: Linux系统默认自带python解释器,版本为python2.7
Python3.8安装
# 切换到root用户parallels@centos-7 ~]$ sudo su[sudo] password for parallels:# 切换到python包所在的路径[root@centos-7 parallels]# cd /home/parallels/Downloads/[root@centos-7 Downloads]# lsPython-3.8.2.tgz# 解包[root@centos-7 Downloads]# tar -zxvf Python-3.8.2.tgz -C /tmp# 配置安装路径[root@centos-7 Python-3.8.2]# ./configure --prefix=/usr/local/Python38# 编译并安装[root@centos-7 Python-3.8.2]# make && make install
报错
缺少依赖包zlib:
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
解决
安装依赖包并重新安装:
[root@centos-7 Python-3.8.2]# yum -y install zlib-devel
[root@centos-7 Python-3.8.2]# make install
出现以下内容表示安装成功
Looking in links: /tmp/tmplorzx9v1
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.2.3 setuptools-41.2.0
环境变量配置
[root@centos-7 ~]# vim /etc/profile
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
PATH=$PATH:/usr/local/Python38/bin
export PATH
重启计算机
[root@centos-7 ~]# reboot
验证
[parallels@centos-7 ~]$ python3
Python 3.8.2 (default, Apr 25 2020, 12:47:21)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
