优选主流主机商
任何主机均需规范使用

如何在CentOS 7系统中一步步安装Python 3:详细教程与常见问题解决

环境搭建

准备工具:

  1. centos7:http://mirror.bit.edu.cn/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1611.iso
  2. virtuslvox:https://www.virtualbox.org/wiki/Downloads
  3. subline
  4. secureCRT

1.装好虚拟机后,添加镜像文件,选择minimal最小化安装

?

1 2 3 yum update #更新软件 yum -y install gcc kernel-devel kenel-headers make bzip2 # 安装依赖库 reboot # 重启

2.挂载执行脚本

?

1 2 3 4 5 mount /dev/cdrom /mnt # 挂载光驱到 mnt 目录 cd /mnt # 进入到mnt目录 sh . /VBoxLinuxAdditions .run # 执行脚本,进行安装   reboot #重启

3.做快照,以便日后恢复

4.python环境的安装(安装pyenv)

centos的配置

?

1 2 3 4 5 $ yum install readline readline-devel readline-static -y $ yum install openssl openssl-devel openssl-static -y $ yum install sqlite-devel -y $ yum install bzip2 -devel bzip2 -libs -y $ yum install patch vim git

安装python3.3/pip3

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #安装python3.3 $ sudo mkdir /usr/local/python3 # 创建安装目录 $ wget --no-check-certificate https: //www .python.org /ftp/python/3 .6.0 /Python-3 .6.0.tgz #下载源文件。注意:wget获取https的时候要加上:--no-check-certificate $ tar -xzvf Python-3.6.0.tgz # 解压缩包 $ cd Python-3.6.0 # 进入解压目录 #编译安装 $ sudo . /configure --prefix= /usr/local/python3 # 指定创建的目录 $ sudo make $ sudo make install #配置2个版本共存 $ sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python3 #创建 python3 的软链接,这样就可以通过 python 命令使用 Python 2,python3 来使用 Python 3。 #修改默认为 Python 3 $ sudo mv python python.bak $ sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python #创建 python3 的软链接 $ sudo vi /usr/bin/yum #因为 yum 使用 Python 2,因此替换为 Python 3 后可能无法正常工作,因此修改 yum 配置文件。将第一行指定的 python 版本改为 python2.7(#!/usr/bin/python 改为 #!/usr/bin/python2.7)

?

1 2 3 4 5 6 7 #源码安装 pip $ wget --no-check-certificate https: //github .com /pypa/pip/archive/9 .0.1. tar .gz # 下载源代码 $ tar -zvxf 9.0.1 -C pip-9.0.1  # 解压文件 $ cd pip-9.0.1 $ python3 setup.py install # 使用 Python 3 安装 $ sudo ln -s /usr/local/python3/bin/pip /usr/bin/pip3 #创建链接 $ pip install --upgrade pip # 升级 pip

安装setuptools

?

1 2 3 tar -xvf setuptools-1.4.2. tar .gz cd setuptools-1.4.2 python setup.py install

 

未经允许不得转载:搬瓦工中文网 » 如何在CentOS 7系统中一步步安装Python 3:详细教程与常见问题解决