2017年2月18日 星期六

[ Python 常見問題 ] How to install Python3 on CentOS

Source From Here
Question
I am trying to install a Python app that requires python3 on CentOS system. However, my CentOS only has python 2.X installed, but not python 3.X. How can I install python3 on CentOS?

How-To
As of the latest CentOS 7, the default Python version still remains python 2.7, and python3 is not available in base repositories. If you need to use python3 as part of Python application dependency, there are several ways to install python3 on CentOS.

Method One: Build and Install Python3 from the Source
You can always build python3 from its source manually. Since you can choose the version of python3 to install, this is the surest way to meet Python dependency requirement. Here is how you can build and install python3 from the source.

First, install minimum necessary tools:
# yum install yum-utils

Then using yum-builddep, set up a necessary build environment for python3 and install missing dependencies. The following command will automatically take care of that.
# yum group install "Development Tools"
# yum-builddep python

Now download the latest python3 (e.g., python 3.5) from https://www.python.org/ftp/python/

Finally, build and install python3 as follows. The default installation directory is /usr/local. If you want to change this to some other directory, pass "--prefix=/alternative/path" parameter to configure before running make.
# tar xf Python-3.5.0.tgz
# cd Python-3.5.0
# ./configure
# make
# make install

This will install python3, pip3, setuptools as well as python3 libraries on your CentOS system.
# python3 --version
Python 3.5.0

If you want to use python3 as your default Python interpreter, you can define the following alias in your .bashrc.
# alias python='/usr/local/bin/python3.5'

Method Two: Install Python3 from EPEL Repository
The latest EPEL 7 repository offers python3 (python 3.4 to be exact). Thus if you are using CentOS 7 or later, you can easily install python3 by enabling EPEL repository as follows.
# yum install epel-release

Then install python 3.4 and its libraries using yum:
# yum install python34

Note that this will not install matching pip. To install pip and setuptools, you need to install them separately as follows.
# curl -O https://bootstrap.pypa.io/get-pip.py
# /usr/bin/python3.4 get-pip.py



Method Three: Install Python3 from Software Collections (SCL)
Another way to install python3 is via enabling Software Collections (SCL) repository. The SCL repository is available for CentOS 6.5 or later, and the latest SCL offers python 3.3. Once you enable the SCL repository, go ahead and install python3 as follows.
# yum install python33

To use python3 from the SCL, you need to enable python3 on a per-command basis as follows.
# scl enable python33

You can also invoke a bash shell with python3 enabled as the default Python interpreter:
# scl enable python33 bash


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...