Linux下多个python版本的安装

前言

开发环境下面,需要安装多版本Python来开发项目
各个版本Python下载地址

0 所需的编译环境

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel python-devel mysql-devel gcc make

1 Python2.7和Python3.5的安装

# python2.7版本下载
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
tar -zxvf Python-2.7.11.tgz
cd Python-2.7.11
# 指定安装路径
./configure --prefix=/usr/local/python27
make && make install

# 软链接添加
ln -sv /usr/local/python27/bin/python /usr/bin/python27
# python3.5版本下载
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar -zxvf Python-3.5.2.tgz
cd Python-3.5.2
# 指定安装路径
./configure --prefix=/usr/local/python35
make && make install

# 软链接添加
ln -sv /usr/local/python35/bin/python /usr/bin/python53

2 pip和setuptools安装

# 安装setuptools
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-20.3.1.tar.gz
tar -xvf setuptools-20.3.1.tar.gz
cd setuptools-20.3.1
python27 setup.py install --prefix=/usr/local/python27
# 安装pip
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.1.tar.gz
tar -zxvf pip-8.0.1.tar.gz
cd pip-8.0.1
python27 setup.py install --prefix=/usr/local/python27

# 软连接添加
ln -sv /usr/local/python27/bin/pip /usr/bin/pip27

3 pip安装软件

pip27 install django==1.8.2 --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org

4 遇到的问题

4.1--enable-shared 出现找不到libpython2.7.so.1.0的情况

./configure --prefix=/usr/local/python27 --enable-shared
[root@spareribs lib]# python27         
python27: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

(2) vi /etc/ld.so.conf 添加/usr/local/Python2.7/lib
/sbin/ldconfig
/sbin/ldconfig -v

[root@localhost bin]# /usr/local/bin/python2.7
/usr/local/bin/python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
[root@localhost bin]# find /|grep libpython2.7.so.1.0
/data/tmp/zjt/soft/Python-2.7.12/libpython2.7.so.1.0
/usr/local/lib/libpython2.7.so.1.0
[root@localhost bin]# cp -a /usr/local/lib/libpython2.7.so.1.0 /usr/lib/
[root@localhost bin]# ldconfig 
[root@localhost bin]# /usr/local/bin/python2.7
Python 2.7.12 (default, Feb 19 2017, 21:42:46) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> 

你可能感兴趣的:(Linux下多个python版本的安装)