目录
1.1 安装运行所依赖的环境
1.2 python 3 的安装包下载
1.3 安装所需编译器
1.4 进入安装
1.4 安装成功检查文件编译
1.5 修改文件配置变量位置
1.6 启动python
1.7 总结
1.1 安装运行所依赖的环境
使用yum安装所依赖的包:yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
1.2 python 3 的安装包下载
输入:wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz,也可以进入这个官网下载其他版本。
这里创建在opt目录下可以查看有这个安装包
解开这个安装包
[root@localhost opt]# tar -zxvf Python-3.7.1.tgz
1.3 安装所需编译器
输入:yum install gcc,按y确认安装。
3.7 版本后需要追加安装:yum install libffi-devel -y
1.4 进入安装
进入安装的目录:cd Python-3.7.1 并选择自己需要安装的路径:./configure -- prefix=prefix=/opt/python3
进入编译
[root@localhost Python-3.7.1]# make
编译安装
[root@localhost Python-3.7.1]# make install
1.4 安装成功检查文件编译
[root@localhost python]# /opt/python/bin/python3.7
Python 3.7.1 (default, Oct 6 2021, 14:46:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
1.5 修改文件配置变量位置
[root@localhost python]# vim /etc/profile
[root@localhost python]# vim /etc/profile
添加此内容
# vim ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/opt/python/bin export PATH
配置完成后输入source ~/.bash_profile 使配置生效
[root@localhost python]# source ~/.bash_profile
查看是否可以正常使用
[root@localhost ~]# python3 -V Python 3.7.1 [root@localhost ~]#
1.6 启动python
配置输入python3即可启动
1.7 总结
启动或者安装验证时要在python加3如果不会是就会启动Linux自带的,python。



