在 CentOS 6 系统上安装最新版 Python3 软件包的 3 种方法

简介:

CentOS 克隆自 RHEL,无需付费即可使用。CentOS 是一个企业级标准的、前沿的操作系统,被超过 90% 的网络主机托管商采用,因为它提供了技术领先的服务器控制面板 cPanel/WHM。

该控制面板使得用户无需进入命令行即可通过其管理一切。

众所周知,RHEL 提供长期支持,出于稳定性考虑,不提供最新版本的软件包。

如果你想安装的最新版本软件包不在默认源中,你需要手动编译源码安装。但手动编译安装的方式有不小的风险,即如果出现新版本,无法升级手动安装的软件包;你不得不重新手动安装。

那么在这种情况下,安装最新版软件包的推荐方法和方案是什么呢?是的,可以通过为系统添加所需的第三方源来达到目的。

可供企业级 Linux 使用的第三方源有很多,但只有几个是 CentOS 社区推荐使用的,它们在很大程度上不修改基础软件包。

这几个推荐的源维护的很好,为 CentOS 提供大量补充软件包。

在本教程中,我们将向你展示,如何在 CentOS 6 操作系统上安装最新版本的 Python 3 软件包。

方法 1:使用 Software Collections 源 (SCL)

SCL 源目前由 CentOS SIG 维护,除了重新编译构建 Red Hat 的 Software Collections 外,还额外提供一些它们自己的软件包。

该源中包含不少程序的更高版本,可以在不改变原有旧版本程序包的情况下安装,使用时需要通过 scl 命令调用。

运行如下命令可以在 CentOS 上安装 SCL 源:

 
  1. # yum install centos-release-scl

检查可用的 Python 3 版本:

 
  1. # yum info rh-python35
  2. Loaded plugins: fastestmirror, security
  3. Loading mirror speeds from cached hostfile
  4. * epel: ewr.edge.kernel.org
  5. * remi-safe: mirror.team-cymru.com
  6. Available Packages
  7. Name : rh-python35
  8. Arch : x86_64
  9. Version : 2.0
  10. Release : 2.el6
  11. Size : 0.0
  12. Repo : installed
  13. From repo : centos-sclo-rh
  14. Summary : Package that installs rh-python35
  15. License : GPLv2+
  16. Description : This is the main package for rh-python35 Software Collection.

运行如下命令从 scl 源安装可用的最新版 python 3:

 
  1. # yum install rh-python35

运行如下特殊的 scl 命令,在当前 shell 中启用安装的软件包:

 
  1. # scl enable rh-python35 bash

运行如下命令检查安装的 python3 版本:

 
  1. # python --version
  2. Python 3.5.1

运行如下命令获取系统已安装的 SCL 软件包列表:

 
  1. # scl -l
  2. rh-python35

方法 2:使用 EPEL 源 (Extra Packages for Enterprise Linux)

EPEL 是 Extra Packages for Enterprise Linux 的缩写,该源由 Fedora SIG (Special Interest Group)维护。

该 SIG 为企业级 Linux 创建、维护并管理了一系列高品质补充软件包,受益的企业级 Linux 发行版包括但不限于红帽企业级 Linux (RHEL)、 CentOS、 Scientific Linux (SL) 和 Oracle Linux (OL)等。

EPEL 通常基于 Fedora 对应代码提供软件包,不会与企业级 Linux 发行版中的基础软件包冲突或替换其中的软件包。

推荐阅读: 在 RHEL, CentOS, Oracle Linux 或 Scientific Linux 上安装启用 EPEL 源

EPEL 软件包位于 CentOS 的 Extra 源中,已经默认启用,故我们只需运行如下命令即可:

 
  1. # yum install epel-release

检查可用的 python 3 版本:

 
  1. # yum --disablerepo="*" --enablerepo="epel" info python34
  2. Loaded plugins: fastestmirror, security
  3. Loading mirror speeds from cached hostfile
  4. * epel: ewr.edge.kernel.org
  5. Available Packages
  6. Name : python34
  7. Arch : x86_64
  8. Version : 3.4.5
  9. Release : 4.el6
  10. Size : 50 k
  11. Repo : epel
  12. Summary : Version 3 of the Python programming language aka Python 3000
  13. URL : http://www.python.org/
  14. License : Python
  15. Description : Python 3 is a new version of the language that is incompatible with the 2.x
  16. : line of releases. The language is mostly the same, but many details, especially
  17. : how built-in objects like dictionaries and strings work, have changed
  18. : considerably, and a lot of deprecated features have finally been removed.

运行如下命令从 EPEL 源安装可用的最新版 python 3 软件包:

 
  1. # yum --disablerepo="*" --enablerepo="epel" install python34

默认情况下并不会安装 pipsetuptools,我们需要运行如下命令手动安装:

 
  1. # curl -O https://bootstrap.pypa.io/get-pip.py
  2. % Total % Received % Xferd Average Speed Time Time Time Current
  3. Dload Upload Total Spent Left Speed
  4. 100 1603k 100 1603k 0 0 2633k 0 --:--:-- --:--:-- --:--:-- 4816k
  5. # /usr/bin/python3.4 get-pip.py
  6. Collecting pip
  7. Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
  8. Collecting setuptools
  9. Downloading https://files.pythonhosted.org/packages/8c/10/79282747f9169f21c053c562a0baa21815a8c7879be97abd930dbcf862e8/setuptools-39.1.0-py2.py3-none-any.whl (566kB)
  10. 100% |████████████████████████████████| 573kB 4.0MB/s
  11. Collecting wheel
  12. Downloading https://files.pythonhosted.org/packages/1b/d2/22cde5ea9af055f81814f9f2545f5ed8a053eb749c08d186b369959189a8/wheel-0.31.0-py2.py3-none-any.whl (41kB)
  13. 100% |████████████████████████████████| 51kB 8.0MB/s
  14. Installing collected packages: pip, setuptools, wheel
  15. Successfully installed pip-10.0.1 setuptools-39.1.0 wheel-0.31.0

运行如下命令检查已安装的 python3 版本:

 
  1. # python3 --version
  2. Python 3.4.5

方法 3:使用 IUS 社区源

IUS 社区是 CentOS 社区批准的第三方 RPM 源,为企业级 Linux (RHEL 和 CentOS) 5、 6 和 7 版本提供最新上游版本的 PHP、 Python、 MySQL 等软件包。

IUS 社区源依赖于 EPEL 源,故我们需要先安装 EPEL 源,然后再安装 IUS 社区源。按照下面的步骤安装启用 EPEL 源和 IUS 社区源,利用该 RPM 系统安装软件包。

推荐阅读: 在 RHEL 或 CentOS 上安装启用 IUS 社区源

EPEL 软件包位于 CentOS 的 Extra 源中,已经默认启用,故我们只需运行如下命令即可:

 
  1. # yum install epel-release

下载 IUS 社区源安装脚本:

 
  1. # curl 'https://setup.ius.io/' -o setup-ius.sh
  2. % Total % Received % Xferd Average Speed Time Time Time Current
  3. Dload Upload Total Spent Left Speed
  4. 100 1914 100 1914 0 0 6563 0 --:--:-- --:--:-- --:--:-- 133k

安装启用 IUS 社区源:

 
  1. # sh setup-ius.sh

检查可用的 python 3 版本:

 
  1. # yum --enablerepo=ius info python36u
  2. Loaded plugins: fastestmirror, security
  3. Loading mirror speeds from cached hostfile
  4. * epel: ewr.edge.kernel.org
  5. * ius: mirror.team-cymru.com
  6. * remi-safe: mirror.team-cymru.com
  7. Available Packages
  8. Name : python36u
  9. Arch : x86_64
  10. Version : 3.6.5
  11. Release : 1.ius.centos6
  12. Size : 55 k
  13. Repo : ius
  14. Summary : Interpreter of the Python programming language
  15. URL : https://www.python.org/
  16. License : Python
  17. Description : Python is an accessible, high-level, dynamically typed, interpreted programming
  18. : language, designed with an emphasis on code readability.
  19. : It includes an extensive standard library, and has a vast ecosystem of
  20. : third-party libraries.
  21. :
  22. : The python36u package provides the "python3.6" executable: the reference
  23. : interpreter for the Python language, version 3.
  24. : The majority of its standard library is provided in the python36u-libs package,
  25. : which should be installed automatically along with python36u.
  26. : The remaining parts of the Python standard library are broken out into the
  27. : python36u-tkinter and python36u-test packages, which may need to be installed
  28. : separately.
  29. :
  30. : Documentation for Python is provided in the python36u-docs package.
  31. :
  32. : Packages containing additional libraries for Python are generally named with
  33. : the "python36u-" prefix.

运行如下命令从 IUS 源安装最新可用版本的 python 3 软件包:

 
  1. # yum --enablerepo=ius install python36u

运行如下命令检查已安装的 python3 版本:

 
  1. # python3.6 --version
  2. Python 3.6.5

原文发布时间为:2018-05-26
本文来自云栖社区合作伙伴“ Linux中国开源社区”,了解相关信息可以关注“ Linux中国开源社区”。
相关文章
|
13天前
|
Python
python魔法方法如何应用
【4月更文挑战第12天】这个Python示例展示了类继承和方法重写。`Student`类继承自`Person`,并覆盖了`say_hello`方法。通过`super().__init__(name)`调用父类的`__init__`初始化`name`属性,`Student`添加了`age`属性,并在重写的`say_hello`中使用。创建`Student`实例`student`并调用其`say_hello`,输出定制的问候信息。
19 1
|
1天前
|
人工智能 Python
【Python实用技能】建议收藏:自动化实现网页内容转PDF并保存的方法探索(含代码,亲测可用)
【Python实用技能】建议收藏:自动化实现网页内容转PDF并保存的方法探索(含代码,亲测可用)
15 0
|
1天前
|
5G Python
Windows11搭建Python环境(Anaconda安装与使用)
Windows11搭建Python环境(Anaconda安装与使用)
9 0
|
6天前
|
存储 关系型数据库 MySQL
Python搭建代理IP池实现存储IP的方法
Python搭建代理IP池实现存储IP的方法
|
6天前
|
Python
Python动态IP代理防止被封的方法
Python动态IP代理防止被封的方法
|
6天前
|
数据采集 存储 安全
python检测代理ip是否可用的方法
python检测代理ip是否可用的方法
|
8天前
|
数据可视化 测试技术 Python
在Python和R中使用交叉验证方法提高模型性能
在Python和R中使用交叉验证方法提高模型性能
20 0
|
8天前
|
存储 监控 开发工具
对象存储OSS产品常见问题之python sdk中的append_object方法支持追加上传xls文件如何解决
对象存储OSS是基于互联网的数据存储服务模式,让用户可以安全、可靠地存储大量非结构化数据,如图片、音频、视频、文档等任意类型文件,并通过简单的基于HTTP/HTTPS协议的RESTful API接口进行访问和管理。本帖梳理了用户在实际使用中可能遇到的各种常见问题,涵盖了基础操作、性能优化、安全设置、费用管理、数据备份与恢复、跨区域同步、API接口调用等多个方面。
38 9
|
8天前
|
Python
python面型对象编程进阶(继承、多态、私有化、异常捕获、类属性和类方法)(上)
python面型对象编程进阶(继承、多态、私有化、异常捕获、类属性和类方法)(上)
50 0
|
10月前
|
Python
28.从入门到精通:Python3 面向对象 面向对象技术简介 类定义 类对象 类的方法
28.从入门到精通:Python3 面向对象 面向对象技术简介 类定义 类对象 类的方法