安装python2.7
wget https://www.Python.org/ftp/Python/2.7.8/Python-2.7.8.tgz
tar xvf Python-2.7.8.tgz
cd Python-2.7.8
./configure –prefix=/usr/local/python27
make
make install
mv /usr/bin/python /usr/bin/python_old
ln -s /usr/local/python27/bin/python /usr/bin/
python # 查看版本
解决YUM无法使用的问题
vim /usr/bin/yum
首行#!/usr/bin/python 替换为老版本python #!/usr/bin/python2.4 注意可能为2.6
pip模块安装
yum install python-pip # centos安装pip
sudo apt-get install python-pip # ubuntu安装pip
pip官方安装脚本
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py
pip编译安装
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e
tar zxvf pip-1.5.6.tar.gz
cd pip-1.5.6
python setup.py build
python setup.py install
加载环境变量
vim /etc/profile
export PATH=/usr/local/python27/bin:$PATH
. /etc/profile
pip install Package # 安装包 pip install requests
pip show –files Package # 查看安装包时安装了哪些文件
pip show –files Package # 查看哪些包有更新
pip install –upgrade Package # 更新一个软件包
pip uninstall Package # 卸载软件包
/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
动态链接的库文件找不到了,解决方法如下
在/etc/ld.so.conf.d/目录下新建一个conf配置文件,起名为python2.7.conf
将python2.7的库目录放入到python2.7.conf中
/usr/local/python27/lib
保存后,运行ldconfig,就可以了