CentOS升级Python2.6到Python2.7

   2016-10-13 0
核心提示:公司机器给的是CentOS 6.X系统,默认安装的Python是2.6版本,恰巧我的程序引用的部分库需要2.7版本或以上,所以需要升级Python到2.7,刚折腾完在这里做个简单的记录 :)0X01 升级pythonCentOs 6.x的系统默认安装的Python版本是2.6.x,想升级到Python2.7.x,从官

公司机器给的是CentOS 6.X系统,默认安装的Python是2.6版本,恰巧我的程序引用的部分库需要2.7版本或以上,所以需要升级Python到2.7,刚折腾完在这里做个简单的记录 :)

0X01 升级python

CentOs 6.x的系统默认安装的Python版本是2.6.x,想升级到Python2.7.x,从官方下载源文件,然后解压、编译

wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz

unxz Python-2.7.10.tar.xz

tar -vxf Python-2.7.10.tar

执行完以上命令会解压得到Python-2.7.10这个文件夹,进入该目录并执行以下命令进行配置

./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib

其中--enable-loadable-sqlite-extensions是sqlite的扩展,如果需要使用的话则带上这个选项。

之后执行

vi ./Modules/Setup

找到#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz去掉注释并保存,然后进行编译和安装

make && make install

安装好Python2.7之后我们需要先把Python2.6备份起来,然后再对yum的配置进行修改,如果不进行这一步操作的话,执行yum命令将会提示你Python的版本不对。

执行以下命令,对Python2.6进行备份,然后为Python2.7创建软链接

mv /usr/bin/python /usr/bin/python2.6.6

ln -s /usr/local/bin/python2.7 /usr/bin/python

然后编辑/usr/bin/yum,将第一行的#!/usr/bin/python修改成#!/usr/bin/python2.6.6

现在执行yum命令已经不会出现之前的错误信息了。

我们执行python -V查看版本信息,如果出现错误

error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

编辑配置文件

vi /etc/ld.so.conf

添加新的一行内容/usr/local/lib,保存退出,然后

/sbin/ldconfig

/sbin/ldconfig -v

0X02 安装pip

下载最新版的pip,然后安装

wget https://bootstrap.pypa.io/get-pip.py

python get-pip.py

查找pip的位置

whereis pip

找到pip2.7的路径,为其创建软链作为系统默认的启动版本

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

pip安装完毕,现在可以用它下载安装各种包了 :)

*本文为 wooyaa 原创,转载请提及 wooyaa 以及原文链接,其他均参照[MIT][15]协议。

 
标签: Python Centos
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • 一个用 Python 分析 Apache 日志的故事
    一个用 Python 分析 Apache 日志的故事
    介绍不久前,公司里有人告诉我“我想知道 Apache 的访问日志是否可以用来做一些事情”。数据分析,Apache,发文章,我是初学者,写的不好请见谅。访问日志分析导入模块我正在使用以下模块。# データの処理import pandas as pdimport numpy as np# グラフ表示i
    03-08
  • debian的python蓝牙库
    sudo apt-get install libglib2.0-devpip install bluepy 
    02-10
  • linux下将Python环境默认更改为Python3.6
    步骤:#删除原来指向python2的软链接sudo mv /usr/bin/python /usr/bin/python.bak #/usr/local/python3.6/bin/python3.6 这个路径为实际的python3.6的bin文件夹下的Python3.6的路径,这个按照自己的实际情况进行更改 sudo ln -s /usr/bin/python3.6 /usr/bin
    02-10
  • 通过python-libvirt管理KVM虚拟机 代码实现
    初步代码 [python] view plain copy span style="font-size:18px;"''''' Work with virtual machines managed by libvirt     :depends: libvirt Python module '''  # Special Thanks to Michael Dehann, many of the conce
    02-10
  • centos安装python与jdk centos安装python3.7
    centos安装python与jdk centos安装python3.7
    安装python#压缩包安装[root@china ~]# yum -y install zlib*Loaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun
    02-10
  • centos6下同时安装python2和python3
    #build-essential compile packagesyum groupinstall "Development Tools"yum install openssl-develyum install zlib-develyum install make gcc gcc-c++ kernel-develhttp://unix.stackexchange.com/questions/291737/zipimport-zipimporterror-cant-decomp
    02-10
  • CentOS7 安装 Python3.8后 pip 安装报错
    [root@localhost Python-3.8.0]# pip install bs4Collecting bs4Using cached https://files.pythonhosted.org/packages/10/ed/7e8b97591f6f456174139ec089c769f89a94a1a4025fe967691de971f314/bs4-0.0.1.tar.gzERROR: Command errored out with exit status
    02-10
  • CentOS 7 - 安装Python 3
    Enable Software Collections (SCL)Software Collections, also known as SCL is a community project that allows you to build, install, and use multiple versions of software on the same system, without affecting system default packages. By enabl
    02-10
  • Nginx+uWSGI部署Python Web应用
    Nginx+uWSGI部署Python Web应用
    web开发的过程中一定会遇到 cgi、wsgi 之类的名词,然后看着他们十分相似的解释估计还没开始写代码就晕了,这都什么鬼? 今天我就聊聊这些容易搞混的名称。CGI(Common Gateway Inteface)  字面的意思就是通用网关接口,它是外部应用程序与Web服务器之间的
    02-10
  • Nginx+uwsgi+python配置
    Nginx+uwsgi+python配置
    版本:Nginx 1.0.5   uwsgi 1.1.2   Python 2.7.2原理: nginx配置 location /python { include uwsgi_params; uwsgi_pass 127.0.0.1:9090;}uwsgi启动参数    uwsgi --socket :9090 --wsgi-file /var/www/project/hello.pyhello.py 文件def appli
    02-10
点击排行