1 安装依赖包
centos7.6是没有自带python3的
[root@opgs201 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@opgs201 ~]# python3
bash: python3: command not found...
Similar command is: 'python'
先挂载iso文件,配置本地yum源
##挂载虚拟机的光盘
mount /dev/cdrom /mnt
#备份原来的yum文件
cd /etc/yum.repos.d
mkdir bk
mv *.repo bk/
##创建一个repo
echo "[EL]" >> /etc/yum.repos.d/linux7.repo
echo "name =LINUX7.DVD" >> /etc/yum.repos.d/linux7.repo
echo "baseurl=file:///mnt" >> /etc/yum.repos.d/linux7.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/linux7.repo
echo "enabled=1" >> /etc/yum.repos.d/linux7.repo
安装依赖包,安装多一点免得又缺了什么
##这个是为了安装一些工具
yum -y groupinstall "Development Tools"
##直接安装python相关依赖
yum -y install make
yum -y install zlib-devel
yum -y install libffi*
yum -y install rng-tools
yum -y install perl
yum -y install sqlite-devel
yum -y install openssl*
yum -y install gcc
yum -y install gcc-c++
yum -y install libcgroup
yum -y install libcgroup-tools
yum -y install bzip2-devel
yum -y install ncurses-devel
yum -y install readline-devel
yum -y install tk-devel
yum -y install gdbm-devel
yum -y install db4-devel
yum -y install libcap-devel
yum -y install xz-devel
yum -y install libffi-devel
yum -y install lzma
systemctl restart rngd
systemctl restart cgconfig
2 下载安装包
https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
##上传到某个目录下
cd /opt
tar -zxvf Python-3.6.8.tgz
3 编译安装python
CONFIGURE
cd Python-3.6.8/
mkdir -p /usr/local/python3
./configure --prefix=/usr/local/python3 --enable-optimizations --enable-shared --with-ssl
make
执行make进行编译
make
或者使用j加速编译
make -sj8
后面可以有这些警告,先不用管
/opt/Python-3.6.8/Modules/xxlimited.c: In function ‘PyInit_xxlimited’:
/opt/Python-3.6.8/Modules/xxlimited.c:304:1: note: file /opt/Python-3.6.8/build/temp.linux-x86_64-3.6/opt/Python-3.6.8/Modules/xxlimited.gcda not found, execution counts estimated
}
^
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
atexit pwd time
make install
直接安装就可以了
make install
创建软链接
ln -snf /usr/local/python3/bin/python3 /usr/bin/python3
ln -sf /usr/local/python3/lib/libpython3.6m.so.1.0 /usr/lib64/libpython3.6m.so.1.0
ln -sf /usr/lib64/libpython3.6m.so.1.0 /usr/lib64/libpython3.6m.so
ln -sf /usr/local/python3/lib/libpython3.so /usr/lib64/libpython3.so
ln -s /usr/lib64/libffi.so.6 /usr/lib64/libffi.so.7
## 不需要把原来的python2都换了
#ln -sf /usr/bin/python3 /usr/bin/python
chmod -R 755 /usr/local/python3
4 验证
[root@opgs201 Python-3.6.8]# python3 -V
Python 3.6.8
[root@opgs201 Python-3.6.8]# python3
Python 3.6.8 (default, Oct 11 2024, 10:50:36)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
标签:3.6,devel,python3.6,源码,yum,usr,install,python3,centos7.6
From: https://www.cnblogs.com/su1999/p/18459499