centos6下同时安装python2和python3
依赖项
#build-essential compile packages
yum groupinstall "Development Tools"
yum install openssl-devel
yum install zlib-devel
yum install make gcc gcc-c++ kernel-devel
安装
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
cd Python-3.*
sudo ./configure
sudo make
sudo make install
注意make install完成后不应该出现Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS之类提示,出现Successfully installed pip-xxx才正确。
默认安装路径是/usr/local,可以通过prefix选项自定义,比如./configure --prefix=/opt/python3
http://stackoverflow.com/questions/8087184/problems-installing-python3-on-rhel
软链接和alias
$ sudo ln -s /usr/local/bin/python3 /usr/bin/python3
$ alias python=/usr/bin/python3
一般python3目录下已经装好pip3了,如果没有,手动安装pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 8.7kB/s
Collecting wheel
Using cached wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: pip, wheel
Found existing installation: pip 8.1.1
Uninstalling pip-8.1.1:
Successfully uninstalled pip-8.1.1
Successfully installed pip-9.0.1 wheel-0.29.0
$ ln -s /usr/local/bin/pip3 pip3
$ alias pip=/usr/bin/pip3
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.5/site-packages (python 3.5)
pyenv
提供更方便的多版本python管理:http://einverne.github.io/post/2017/04/pyenv.html
作者:kakashis
联系方式:fengshenjiev[AT]gmail.com
本文版权归作者所有,欢迎转载,演绎或用于商业目的,但是必须说明本文出处(包含链接)。