Centos 7でpython 2.xとpython 3.x共存
サマリ
現在centos 7システムに付属しているPythonバージョンは2.7.5で、このバージョンではシステムの多くのプログラムロックに依存しており、削除することはできません.もしこの時python 3を使いたいなら.xバージョンは、pyenvを利用して純粋なpython 3を作成する2つの方法があります.x環境、Centosの下でpythonの純粋な仮想環境を参照することができます;もう一つはここで紹介したものです.
ダウンロード
に頼る
正式にインストールする前に、後続のインストールが正常に行われることを保証するために、いくつかの依存をインストールする必要があります.
インストール
検証#ケンショウ#
現在centos 7システムに付属しているPythonバージョンは2.7.5で、このバージョンではシステムの多くのプログラムロックに依存しており、削除することはできません.もしこの時python 3を使いたいなら.xバージョンは、pyenvを利用して純粋なpython 3を作成する2つの方法があります.x環境、Centosの下でpythonの純粋な仮想環境を参照することができます;もう一つはここで紹介したものです.
ダウンロード
root@pts/0 $ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
--2018-01-11 17:13:58-- https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:36::223
www.python.org (www.python.org)|151.101.228.223|:443... 。
HTTP , ... 200 OK
:22540566 (21M) [application/octet-stream]
: “Python-3.6.1.tgz”
100%[=========================================================================================>] 22,540,566 3.34MB/s 7.8s
2018-01-11 17:14:06 (2.74 MB/s) - “Python-3.6.1.tgz” [22540566/22540566])
に頼る
正式にインストールする前に、後続のインストールが正常に行われることを保証するために、いくつかの依存をインストールする必要があります.
yum install -y gcc gcc-c++ autoconf automake zlib-devel
インストール
#
root@pts/0 $ tar -zxf Python-3.6.1.tgz
root@pts/0 $ ll
26112
drwxr-xr-x 17 501 501 4096 3 21 2017 Python-3.6.1
-rw-r--r-- 1 root root 22540566 3 21 2017 Python-3.6.1.tgz
#
/usr/local 。 configure --prefix ,
root@pts/0 $ cd Python-3.6.1
root@pts/0 $ ./configure --prefix=/usr/local/python3
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for python3.6... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
#
root@pts/1 $ make && make install
検証#ケンショウ#
root@pts/1 $ ls -l /usr/local/python3/
16
drwxr-xr-x 2 root root 4096 1 11 17:09 bin
drwxr-xr-x 3 root root 4096 1 11 17:09 include
drwxr-xr-x 4 root root 4096 1 11 17:09 lib
drwxr-xr-x 3 root root 4096 1 11 17:09 share
root@pts/1 $ /usr/local/python3/bin/python3 -V
Python 3.6.1
root@pts/1 $ /usr/local/python3/bin/python3
Python 3.6.1 (default, Jan 11 2018, 17:08:20)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>