centos7安装python3.7.7
原地址
- 准备工作,切换root用户 提前装好libffi-devel模块(装好的跳过),安装好依赖
1-yum install libffi-devel -y
2-yum -y groupinstall "Development tools"
3-yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel
4-sqlite-devel readline-devel tk-devel gdbm-devel db4-devel
5-libpcap-devel xz-devel yum install -y libffi-devel zlib1g-dev yum
6-install zlib* -y
- 下载安装
1-wget wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tar.xz//下载安装包3.7.7
2-tar -xvJf Python-3.7.7.tar.xz//直接解压到当前文件夹
3-mkdir /usr/local/python3//创建一个python编译目录
4-cd Python-3.7.7//切换到python3.7.7目录
5-./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl//设置安装路径和ssl
6-make && make install//开始编译(时间会比较长)
成功的话,最后会出现 successfully installed…
- 设置软连接
1-ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
2-ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
结束
- PSS
此时在centos7中编写python3版本的脚本***.py时,无法通过如下编译
#!/usr/bin/python3
这当于写死了python3路径,安装结束时,系统默认Python版本是Python2。只能通过env去环境中寻找Python3.如下所示:
#!/usr/bin/env python3
当系统看到这一行的时候,首先会到env设置里查找python3的安装路径,再调用对应路径下的解释器程序完成操作,推荐这种写法。