因为个人需要,整理的
操作系统:1.CentOS7(已测试)
2.ubuntu16.04(anaconda已测试,其他方法可能会缺少某些系统文件)
说明
- 最新版本:2.7.16/3.6.8/3.7.3
安装方法
1. 编译安装
1.1 Python2
版本
Python2.7.12 (PS:centos7自带Python2.7.5,一般无需额外安装python2)
Python包
https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
Setuptools包
https://files.pythonhosted.org/packages/1d/64/a18a487b4391a05b9c7f938b94a16d80305bf0369c6b0b9509e86165e1d3/setuptools-41.0.1.zip
pip包
https://files.pythonhosted.org/packages/93/ab/f86b61bef7ab14909bd7ec3cd2178feb0a1c86d451bc9bccd5a1aedcde5f/pip-19.1.1.tar.gz
安装目录
/usr/local/services/python27
Python安装
tar zxvf Python-2.7.12.tar.xz -C /tmp
cd /tmp/Python-2.7.12
./configure --prefix=/usr/local/services/python27
make && make install
pip安装
unzip setuptools-41.0.1.zip -d /tmp
cd /tmp/setuptools-41.0.1
/usr/local/services/python27/bin/python setup.py install
tar zxvf pip-19.1.1.tar.gz -C /tmp
cd /tmp/pip-19.1.1
/usr/local/services/python27/bin/python setup.py install
更新pip源
mkdir -p $HOME/.config/pip/
echo "[global]
timeout = 6000
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com" > $HOME/.config/pip/pip.conf
1.2 Python3
版本
Python3.6.8
Python包
https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
安装目录
/usr/local/services/python36
tkinter安装
yum -y install tkinter
yum -y install tcl-devel tk-devel
Python安装
xz -d Python-3.6.8.tar.xz
tar -xvf Python-3.6.8.tar -C /tmp
cd /tmp/Python-3.6.8
./configure --prefix=/usr/local/services/python-3.6.8 --enable-shared CFLAGS=-fPIC
make && make install
echo "/usr/local/services/python-3.6.8/lib" > /etc/ld.so.conf.d/python3.6.conf
ldconfig
更新pip源
mkdir -p $HOME/.config/pip/
echo "[global]
timeout = 6000
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com" > $HOME/.config/pip/pip.conf
ln -snf /usr/local/services/python-3.6.8 /usr/local/services/python3
ln -snf /usr/local/services/python3/bin/python3 /usr/local/services/python3/bin/python
ln -snf /usr/local/services/python3/bin/pip3 /usr/local/services/python3/bin/pip
# python3
export PATH="/usr/local/services/python3/bin:$PATH"
# 安装依赖库
yum install -y gmp-devel mpfr-devel libmpc-devel unixODBC-devel
yum install -y cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib
2. anaconda安装
2.1 anaconda3
版本
Anaconda3-5.2.0
官网
https://www.anaconda.com/download/#linux
anaconda3
https://repo.continuum.io/archive/Anaconda3-5.2.0-Linux-x86_64.sh
安装
bash Anaconda3-5.2.0-Linux-x86_64.sh
修改安装路径
Do you accept the license terms? [yes|no]
Please answer 'yes' or 'no':'
>>> yes
Anaconda3 will now be installed into this location:
/root/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/anaconda3] >>> /usr/local/services/anaconda3
PREFIX=/usr/local/services/anaconda3
手动添加环境变量
installation finished.
Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /root/.bashrc ? [yes|no]
[no] >>>
You may wish to edit your .bashrc to prepend the Anaconda3 install location to PATH:
export PATH=/opt/modules/anaconda3/bin:$PATH
Thank you for installing Anaconda3!
vim /etc/profile
末尾添加
export PATH=/opt/modules/anaconda3/bin:$PATH
保存退出
source /etc/profile
3. pyenv安装 (还未测试)
- 安装简单
- 多版本管理方便
- 环境切换简单