Upgrade Python And Pip On CentOS 6.x

来源:互联网 发布:大数据 消费者洞察 编辑:程序博客网 时间:2024/05/22 00:09

下载python2.7源码,编译安装

安装opensslopenssl-devel

# yum install openssl # yum install openssl-devel

进入python源代码文件夹,修改Modules/Setup.dist文件

#vim Setup.dist修改# Socket module helper for SSL support; you must comment out the other# socket line above, and possibly edit the SSL variable:#SSL=/usr/local/ssl#_ssl _ssl.c \#        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \#        -L$(SSL)/lib -lssl -lcrypto# Socket module helper for SSL support; you must comment out the other# socket line above, and possibly edit the SSL variable:SSL=/usr/local/ssl_ssl _ssl.c \        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \        -L$(SSL)/lib -lssl -lcrypto

安装python

# ./configure --prefix=/usr/local/python2.7# make all# make install

替换原有python2.6版本

# rm -rf /usr/bin/python# ln -s /usr/local/python2.7/bin/python /usr/bin/# vim /usr/bin/yumTo:#!/usr/bin/python2.6...

重新安装pip

安装setuptools:

# curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python

安装pip

easy_install pip

此时pip安装在新版python目录的bin目录: /usr/local/python2.7/bin/下
需要软链到/usr/bin/pip下方能正常使用

# ln -s /usr/local/python2.7/bin/pip2.7 /usr/bin/pip

测试

# pip install pymongoCollecting pymongo  Downloading http://pypi.douban.com/packages/source/p/pymongo/pymongo-3.2.tar.gz (473kB)    100% |████████████████████████████████| 475kB 1.0MB/s Installing collected packages: pymongo  Running setup.py install for pymongoSuccessfully installed pymongo-3.2# pythonPython 2.7.11 (default, Dec 22 2015, 13:41:47) [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import pymongo>>> 

End!

相关问题:

1, 升级python2.6到2.7以后执行pip会报这个错误:

Traceback (most recent call last):  File "/var/www/mydir/virtualenvs/dev/bin/pip", line 5, in <module>    from pkg_resources import load_entry_pointImportError: No module named pkg_resources

重新安装一下setuptools即可解决:

curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python

2, python自带url库默认不支持https导致在执行安装setuptools是出错:

urllib2.URLError: <urlopen error unknown url type: https> 

解决办法参考文章上面修改:Modules/Setup.dist部分

相关链接:
https://pypi.python.org/pypi/distribute/0.6.10

0 0
原创粉丝点击