Centos 配置 python2.7

1.下载指定版本包

1
wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz

2.解压

1
tar xf Python-2.7.14.tar.xz

3.编译

1
2
3
cd Python-2.7.14
./configure --prefix=/usr/local/puthon2 --enable-shared --optimazation
make && make altinstall

4.建立软连接

1
ln -sf /usr/local/python2/bin/python2.7 /usr/bin/python

PS:删除软连接

1
rm /usr/bin/python
## 5.运行

1
python

出错: error while loading shared libraries: libpython2.7.so.1.0。。。 解决,编辑 /etc/ld.so.conf 文件,将安装路径的lib目录加入:

1
vim /etc/ld.so.conf 

这里应加入 /usr/local/lib 再次运行

1
python

成功

题外,npm install 构建项目的时候,提示 python2.7 命令不可用,原因是前面软连接为python命令,此时删除原来软连接,建立python2.7 软连接命令

1
ln -sf /usr/local/python2/bin/python2.7 /usr/bin/python2.7