Python 牵手 MySQL

原创 2017年08月18日 21:08:39
安装python
 wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2rc2.tgz
 tar -xvf Python-3.6.2rc2.tgz
 cd Python-3.6.2rc2
 make
 make install
 mv /usr/bin/python /usr/bin/python2.7.5.old
 ln -s /usr/local/python3.6.2/bin/python3.6 /usr/bin/python
 ln -s /usr/local/python3.6.2/bin/python3.6 /usr/bin/python3

 修改yum的python
 vim /usr/bin/yum
 #!/usr/bin/python修改成 #!/usr/bin/python2.7.5.old
 这是因为yum默认使用的python版本是2.7.5,到哪是现在的python版本是3.6,故会出现上述问题,只需要该一下yum的默认python配置版本就行了:



 下载python-mysql
 https://pypi.python.org/pypi/MySQL-python/1.2.5
 下载wget https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
 unzip MySQL-python-1.2.5.zip

 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



yum install -y MySQL-python

报错:
[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ python setup.py build
sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    metadata, options = get_config()
  File "/home/laobanzhang/software/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/home/laobanzhang/software/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ 

解决:
find / -name python;找到python路径/usr/bin/python,所以在/etc/profile里面末尾配置python路径

export PATH=/usr/bin/:$PATH

报错:
[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
_mysql.c:29:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1
[root@huayuan]  


解决: yum -y install mysql-devel libxml2 libxml2-dev libxslt* zlib gcc openssl

[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ python setup.py build
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
creating build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
_mysql.c:29:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

解决:yum install python-devel -y

再执行命令:
python setup.py build
python setup.py install


测试是否能链接
[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ python
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.pyc, but /home/laobanzhang/software/MySQL-python-1.2.5 is being added to sys.path
>>> 

牵手小吉界面

  • 2017年07月22日 11:18
  • 5.9MB
  • 下载

物联网牵手云计算的 两大关键

  • 2010年05月12日 17:45
  • 1.53MB
  • 下载

阿里巴巴牵手福特 共同打造智联网汽车

点击有惊喜 盖世汽车讯,12月7日,阿里巴巴集团和福特汽车公司正式签署战略合作。双方将开展全面合作,共同推进智联网汽车、人工智能、智能移动服务和数字营销等领域的合作。 ...

物联网牵手云计算的两大关键

  • 2010年10月10日 15:34
  • 364KB
  • 下载

情侣牵手、结婚纪念日小助手

  • 2011年05月19日 20:35
  • 1.81MB
  • 下载

牵手阿里,魅族能否成就“更大格局”?

在阿里巴巴正式发布了其操作系统产品“YunOS 3.0”之后,魅族即与阿里联合推出了基于YunOS 3.0的Flyme 4系统——Flyme powered by YunOS(适配于其不久前推出的魅族...

华为Mate 10牵手Microsoft Translator,让离线翻译可媲美在线神经网络翻译

编者按:日前,华为新发布的Mate 10手机系列采用Microsoft Translator技术实现了AI驱动型离线翻译功能。华为Mate 10是首款具有NPU(专用神经处理单元)的手机,可用于加速A...

Lua篇(第02章):Demo讲解之Lua和C++牵手

本章我们来学习一个小Demo,也就是上一章中的场景:C++从Lua中获取一个全局变量的字符串。   正文:   1. 引入头文件 我们来看看要在C++中使用Lua,需要些什么东西 ...

百度牵手大悦城 相爱相杀的零售与互联网需要新玩法

国内互联网发展一直以来可以说有两条主线:一条是技术层面的,包括云计算、大数据和人工智能等方向;一条是商业层面的,主要表现为互联网与传统行业的融合。这种融合诞生了多种形态,例如网络视频、在线教育、在线医...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Python 牵手 MySQL
举报原因:
原因补充:

(最多只允许输入30个字)