CentOS6.6自带的Python版本为2.6.6,想给他升级一下,安装Python2.7.9
一、准备安装包
wgethttps://bootstrap.pypa.io/get-pip.py#下载setuptools和pip wgethttps://pypi.python.org/packages/source/i/ipython/ipython-3.1.0.tar.gz#下载ipython wgethttps://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz#下载python
二、安装依赖包
安装readline-devel,使python安装完成后支持退格;安装gcc,否则配置时会报错,导致无法安装;还有一些扩展模块
yum-yinstallreadline-devel yum-yinstallgcc yum-yinstallzlib-developenssl-develsqlite-devel
三、安装python2.7.9
由于下载的python包为xz格式的,所以解压tar.xz文件需要先xz -d xxx.tar.xz,再tar zvf命令将xxx.tar解包
xz-dPython-2.7.9.tar.xz tarxvfPython-2.7.9.tar cdPython-2.7.9 ./configure--prefix=/usr/local/python make&&makeinstall mv/usr/bin/python/usr/bin/python2.6.6#把之前版本的python重命名 ln-sv/usr/local/python/bin/python2.7/usr/bin/python [root@MidApp~]#python Python2.7.9(default,Nov222017,09:37:44) [GCC4.4.720120313(RedHat4.4.7-18)]onlinux2 Type"help","copyright","credits"or"license"formoreinformation. >>>importssl >>>
四、安装ipython
也完全可以先安装pip,再使用pip install ipython 安装ipython
tarzxvfipython-3.1.0.tar.gz cdipython-3.1.0 pythonsetup.pybuild pythonsetup.pyinstall ln-sv/usr/local/python/bin/ipython/usr/bin/ipython [root@MidApp~]#ipython WARNING:IPythonHistoryrequiressqlite,yourhistorywillnotbesaved Python2.7.9(default,09:37:44) Type"copyright","credits"or"license"formoreinformation. IPython3.1.0--AnenhancedInteractivePython. ?->IntroductionandoverviewofIPython'sfeatures. %quickref->Quickreference. help->Python'sownhelpsystem. object?->Detailsabout'object',use'object??'forextradetails. In[1]:importsys In[2]:3+2 Out[2]:5 In[3]:
五、安装setuptools和pip
命令行里直接下面执行命令就行
pythonget-pip.py [root@MidApp~]#piplist ipython(3.1.0) numpy(1.13.3) pip(9.0.1) setuptools(37.0.0) wheel(0.30.0)
六、我在这里遇到了几个坑,很麻烦:
1、安装pip时,遇到zipimport.ZipImportError: can’t decompress data这种错误
解决方法:
vimPython-2.7.9/Modules/Setup
找到下面地方,去掉注释
zlibzlibmodule.c-I$(prefix)/include-L$(exec_prefix)/lib-lz
然后再使用
make&&makeinstall
重新编译一下python
2、再次安装pip时遇到下列错误:
pipisconfiguredwithlocationsthatrequireTLS/SSL,howeverthesslmoduleinPythonisnotavailable. Collectingsix CouldnotfetchURL https://pypi.python.org/simple/six/: Therewasaproblemconfirmingthesslcertificate:Can'tconnecttoHTTPSURLbecausetheSSLmoduleisnotavailable.-skipping Couldnotfindaversionthatsatisfiestherequirementsix(fromversions:) Nomatchingdistributionfoundforsix
解决方法:
vimPython-2.7.9/Modules/Setup
SSL=/usr/local/ssl _ssl_ssl.c\ -DUSE_SSL-I$(SSL)/include-I$(SSL)/include/openssl\ -L$(SSL)/lib-lssl-lcrypto
然后再使用
make&&makeinstall
3、安装完新的python版本之后,奇怪的发现yum命令不能使用了
解决方法:原来yum命令依赖于python环境,需要改一下yum所调用的python的路径变量。
[root@MidApp~]#whichyum /usr/bin/yum [root@MidApp~]#vim/usr/bin/yum
修改第一行:
#!/usr/bin/python2.6.6
再次使用yum命令,OK!
原文链接:https://www.f2er.com/centos/375225.html