在CentOS 6系統(tǒng)上安裝最新版Python3軟件包的3種方法
CentOS 克隆自 RHEL,無(wú)需付費(fèi)即可使用。CentOS 是一個(gè)企業(yè)級(jí)標(biāo)準(zhǔn)的、前沿的操作系統(tǒng),被超過(guò) 90% 的網(wǎng)絡(luò)主機(jī)托管商采用,因?yàn)樗峁┝思夹g(shù)領(lǐng)先的服務(wù)器控制面板 cPanel/WHM。
該控制面板使得用戶無(wú)需進(jìn)入命令行即可通過(guò)其管理一切。
眾所周知,RHEL 提供長(zhǎng)期支持,出于穩(wěn)定性考慮,不提供***版本的軟件包。
如果你想安裝的***版本軟件包不在默認(rèn)源中,你需要手動(dòng)編譯源碼安裝。但手動(dòng)編譯安裝的方式有不小的風(fēng)險(xiǎn),即如果出現(xiàn)新版本,無(wú)法升級(jí)手動(dòng)安裝的軟件包;你不得不重新手動(dòng)安裝。
那么在這種情況下,安裝***版軟件包的推薦方法和方案是什么呢?是的,可以通過(guò)為系統(tǒng)添加所需的第三方源來(lái)達(dá)到目的。
可供企業(yè)級(jí) Linux 使用的第三方源有很多,但只有幾個(gè)是 CentOS 社區(qū)推薦使用的,它們?cè)诤艽蟪潭壬喜恍薷幕A(chǔ)軟件包。
這幾個(gè)推薦的源維護(hù)的很好,為 CentOS 提供大量補(bǔ)充軟件包。
在本教程中,我們將向你展示,如何在 CentOS 6 操作系統(tǒng)上安裝***版本的 Python 3 軟件包。
方法 1:使用 Software Collections 源 (SCL)
SCL 源目前由 CentOS SIG 維護(hù),除了重新編譯構(gòu)建 Red Hat 的 Software Collections 外,還額外提供一些它們自己的軟件包。
該源中包含不少程序的更高版本,可以在不改變?cè)信f版本程序包的情況下安裝,使用時(shí)需要通過(guò) scl
命令調(diào)用。
運(yùn)行如下命令可以在 CentOS 上安裝 SCL 源:
# yum install centos-release-scl
檢查可用的 Python 3 版本:
# yum info rh-python35
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* epel: ewr.edge.kernel.org
* remi-safe: mirror.team-cymru.com
Available Packages
Name : rh-python35
Arch : x86_64
Version : 2.0
Release : 2.el6
Size : 0.0
Repo : installed
From repo : centos-sclo-rh
Summary : Package that installs rh-python35
License : GPLv2+
Description : This is the main package for rh-python35 Software Collection.
運(yùn)行如下命令從 scl
源安裝可用的***版 python 3:
# yum install rh-python35
運(yùn)行如下特殊的 scl
命令,在當(dāng)前 shell 中啟用安裝的軟件包:
# scl enable rh-python35 bash
運(yùn)行如下命令檢查安裝的 python3 版本:
# python --version
Python 3.5.1
運(yùn)行如下命令獲取系統(tǒng)已安裝的 SCL 軟件包列表:
# scl -l
rh-python35
方法 2:使用 EPEL 源 (Extra Packages for Enterprise Linux)
EPEL 是 Extra Packages for Enterprise Linux 的縮寫(xiě),該源由 Fedora SIG (Special Interest Group)維護(hù)。
該 SIG 為企業(yè)級(jí) Linux 創(chuàng)建、維護(hù)并管理了一系列高品質(zhì)補(bǔ)充軟件包,受益的企業(yè)級(jí) Linux 發(fā)行版包括但不限于紅帽企業(yè)級(jí) Linux (RHEL)、 CentOS、 Scientific Linux (SL) 和 Oracle Linux (OL)等。
EPEL 通常基于 Fedora 對(duì)應(yīng)代碼提供軟件包,不會(huì)與企業(yè)級(jí) Linux 發(fā)行版中的基礎(chǔ)軟件包沖突或替換其中的軟件包。
推薦閱讀: 在 RHEL, CentOS, Oracle Linux 或 Scientific Linux 上安裝啟用 EPEL 源
EPEL 軟件包位于 CentOS 的 Extra 源中,已經(jīng)默認(rèn)啟用,故我們只需運(yùn)行如下命令即可:
# yum install epel-release
檢查可用的 python 3 版本:
# yum --disablerepo="*" --enablerepo="epel" info python34
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* epel: ewr.edge.kernel.org
Available Packages
Name : python34
Arch : x86_64
Version : 3.4.5
Release : 4.el6
Size : 50 k
Repo : epel
Summary : Version 3 of the Python programming language aka Python 3000
URL : http://www.python.org/
License : Python
Description : Python 3 is a new version of the language that is incompatible with the 2.x
: line of releases. The language is mostly the same, but many details, especially
: how built-in objects like dictionaries and strings work, have changed
: considerably, and a lot of deprecated features have finally been removed.
運(yùn)行如下命令從 EPEL 源安裝可用的***版 python 3 軟件包:
# yum --disablerepo="*" --enablerepo="epel" install python34
默認(rèn)情況下并不會(huì)安裝 pip
和 setuptools
,我們需要運(yùn)行如下命令手動(dòng)安裝:
# curl -O https://bootstrap.pypa.io/get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1603k 100 1603k 0 0 2633k 0 --:--:-- --:--:-- --:--:-- 4816k
# /usr/bin/python3.4 get-pip.py
Collecting pip
Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/8c/10/79282747f9169f21c053c562a0baa21815a8c7879be97abd930dbcf862e8/setuptools-39.1.0-py2.py3-none-any.whl (566kB)
100% |████████████████████████████████| 573kB 4.0MB/s
Collecting wheel
Downloading https://files.pythonhosted.org/packages/1b/d2/22cde5ea9af055f81814f9f2545f5ed8a053eb749c08d186b369959189a8/wheel-0.31.0-py2.py3-none-any.whl (41kB)
100% |████████████████████████████████| 51kB 8.0MB/s
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-10.0.1 setuptools-39.1.0 wheel-0.31.0
運(yùn)行如下命令檢查已安裝的 python3 版本:
# python3 --version
Python 3.4.5
方法 3:使用 IUS 社區(qū)源
IUS 社區(qū)是 CentOS 社區(qū)批準(zhǔn)的第三方 RPM 源,為企業(yè)級(jí) Linux (RHEL 和 CentOS) 5、 6 和 7 版本提供***上游版本的 PHP、 Python、 MySQL 等軟件包。
IUS 社區(qū)源依賴于 EPEL 源,故我們需要先安裝 EPEL 源,然后再安裝 IUS 社區(qū)源。按照下面的步驟安裝啟用 EPEL 源和 IUS 社區(qū)源,利用該 RPM 系統(tǒng)安裝軟件包。
推薦閱讀: 在 RHEL 或 CentOS 上安裝啟用 IUS 社區(qū)源
EPEL 軟件包位于 CentOS 的 Extra 源中,已經(jīng)默認(rèn)啟用,故我們只需運(yùn)行如下命令即可:
# yum install epel-release
下載 IUS 社區(qū)源安裝腳本:
# curl 'https://setup.ius.io/' -o setup-ius.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1914 100 1914 0 0 6563 0 --:--:-- --:--:-- --:--:-- 133k
安裝啟用 IUS 社區(qū)源:
# sh setup-ius.sh
檢查可用的 python 3 版本:
# yum --enablerepo=ius info python36u
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* epel: ewr.edge.kernel.org
* ius: mirror.team-cymru.com
* remi-safe: mirror.team-cymru.com
Available Packages
Name : python36u
Arch : x86_64
Version : 3.6.5
Release : 1.ius.centos6
Size : 55 k
Repo : ius
Summary : Interpreter of the Python programming language
URL : https://www.python.org/
License : Python
Description : Python is an accessible, high-level, dynamically typed, interpreted programming
: language, designed with an emphasis on code readability.
: It includes an extensive standard library, and has a vast ecosystem of
: third-party libraries.
:
: The python36u package provides the "python3.6" executable: the reference
: interpreter for the Python language, version 3.
: The majority of its standard library is provided in the python36u-libs package,
: which should be installed automatically along with python36u.
: The remaining parts of the Python standard library are broken out into the
: python36u-tkinter and python36u-test packages, which may need to be installed
: separately.
:
: Documentation for Python is provided in the python36u-docs package.
:
: Packages containing additional libraries for Python are generally named with
: the "python36u-" prefix.
運(yùn)行如下命令從 IUS 源安裝***可用版本的 python 3 軟件包:
# yum --enablerepo=ius install python36u
運(yùn)行如下命令檢查已安裝的 python3 版本:
# python3.6 --version
Python 3.6.5