升级Python

系统默认安装的Python是2.6.6的,我们需要升级到Python2.7,用wget命令从官方下载源文件,然后解压进行编译

wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xzunxz 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
make clean
make distclean

安装好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


上传setuptools-0.6c11-py2.7.egg
[root@VM_0_201_centos python2.7]# sh setuptools-0.6c11-py2.7.egg 
Processing setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to /usr/local/lib/python2.7/site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin

Installed /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11

安装pip

easy_install pip

安装mysqldb

[root@VM_0_201_centos photomanager]# pip install mysql-python

Collecting mysql-python

  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f78d44684d0>, 'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/mysql-python/

  Downloading MySQL-python-1.2.5.zip (108kB)

    100% |################################| 112kB 8.9kB/s 

    Complete output from command python setup.py egg_info:

    sh: mysql_config: command not found

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/tmp/pip-build-5U4VYi/mysql-python/setup.py", line 17, in <module>

        metadata, options = get_config()

      File "setup_posix.py", line 43, in get_config

        libs = mysql_config("libs_r")

      File "setup_posix.py", line 25, in mysql_config

        raise EnvironmentError("%s not found" % (mysql_config.path,))

    EnvironmentError: mysql_config not found

    

    ----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-5U4VYi/mysql-python/


查看centos版本

cat /etc/redhat-release

查看当前mariadb版本

[root@VM_0_201_centos yum.repos.d]# yum list|grep Maria

添加 mariadb源

[root@VM_0_201_centos soft]# cd /etc/yum.repos.d/

[root@VM_0_201_centos yum.repos.d]# ls

CentOS-Base.repo  CentOS-Epel.repo

[root@VM_0_201_centos yum.repos.d]# vi MariaDB.repo

[mariadb] 

name = MariaDB

baseurl = http://yum.mariadb.org/5.5/centos6-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1  


[root@VM_0_201_centos yum.repos.d]# yum install MariaDB-devel.x86_64


[root@VM_0_201_centos yum.repos.d]# pip install mysql-python

Collecting mysql-python

  Using cached MySQL-python-1.2.5.zip

Installing collected packages: mysql-python

  Running setup.py install for mysql-python ... done

Successfully installed mysql-python-1.2.5

(如果仍不行,有可能需要安装python-devel)