下载MySQL-python-1.2.3.tar.gz
进入到MySQL-python目录运行 python setup.py install 出现错误。
因为要使用setup.py需要安装python-setuptools
下面是setuptools安装:
· 下载 http://peak.telecommunity.com/dist/ez_setup.py
· 运行 python ez_setup.py
再一次进入到MySQL-python目录运行python setup.py install
再次出现错误:
sh: mysql_config: not found
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "/root/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/root/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
用find / -name mysql_config命令在系统里查找mysql_config,
结果为空,原因是libmysqlclient-dev库没有装上。
于是 apt-get install libmysqlclient-dev
再查询一次mysql_config文件,
可以得到该文件的地址,我这里是/usr/bin/mysql_config
编辑site.cfg文件,修改mysql_config变量为上面的地址:
mysql_config = /usr/bin/mysql_config
然后再运行python setup.py install,
又提示错误:
In file included from _mysql.c:29:
pymemcompat.h:10:20: error: Python.h: No such file or directory
_mysql.c:30:26: error: structmember.h: No such file or directory
In file included from /usr/include/mysql/mysql.h:44,
from _mysql.c:40:
.
.
.
_mysql.c:2808: warning: return type defaults to 'int'
_mysql.c: In function 'DL_EXPORT':
_mysql.c:2808: error: expected declaration specifiers before 'init_mysql'
_mysql.c:2886: error: expected '{' at end of input
error: command 'gcc' failed with exit status 1
经过google,这里还需要装python-dev库,
果断安装之:
apt-get install python-dev
再一次python setup.py install,
终于成功装上MySQLDB:
nigelzeng@ubuntu:/usr/local/src/MySQL-python-1.2.3$ sudo python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1088:1: warning: "HAVE_WCSCOLL" redefined
In file included from /usr/include/python2.6/Python.h:8,
from pymemcompat.h:10,
from _mysql.c:29:
/usr/include/python2.6/pyconfig.h:808:1: warning: this is the location of the previous definition
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-i686-2.6/_mysql.o -L/usr/lib/mysql -lmysqlclient_r -o build/lib.linux-i686-2.6/_mysql.so
最后install:
sudo python setup.py install
搞定!
+——————————————————————————————————————————+
setuptools:
介绍setuptools,就要从distutils讲起。Distutils属于Python的标准库,是从版本1.6以来就有的,其作用,主要是用来创建和使用安装包,我们常见的setup.py就是基于这个工具集创建,并且被这个工具集所使用的。这个模块的主要功能都在distutils.core里面,作为开发者,通常是导入distutils.core中的setup,来创建一个setup.py文件。
setuptools,则是在distutils基础上的一个增强包,提高了创建分发包,使用分发包的能力。在这个增强的模块里面,新增加了easy_install.py,同时开始支持egg文件的构建和使用。对开发者来说,增加了MANIFEST,PyReg,PYPI等特性。
这里,要提一下常用到的egg文件,egg文件,就像是java中的jar包,把代码和资源打包起来成为一个zip压缩包,并且冠于egg后缀。
分享到:
相关推荐
python安装模块MySQLdb时,提示python2.7未安装,安装失败时,命令行python register.py,然后重新安装MySQLdb,就能正确安装。
这个包里有两个包,都可以用来在windows上安装python-MySQLdb,选择其中一种就可以!我比较喜欢用-master那个包,因为只要解压后执行python setup.py install就可以了。另一个包在安装时若出现找不到python2.7的安装...
windows下Python,Django安装MySQLdb需要的2个ddl文件之一libguide40.dll.zip
python的mysqldb安装步骤详解 安装MySQLdb: 一、 什么是MySQLdb? 解释:MySQLdb是Python操作MySQL的一个接口包。这里要理解一个概念,python操作数据库,都是需要一个类似MySQLdb这样的中间层,这些中间层抽象了...
windows环境下配置python3 mysqldb
python2.7.5安装mysqldb失败, my_config.h: No such file or directory. 解决办法:1)mysql版本太高,可降低版本 --此路一般不会考虑 2)注意下载的mysql-python的版本是否符和当前版本兼容 2)下载附件中的文件,...
python3.6使用MySQLdb连接mysql需要mysqlclient-1.3.12-cp36-cp36m-win_amd64.whl
python连接mysql数据库需要MySQLdb win7 64位安装好就可以用了。 具体代码可以参考:http://www.runoob.com/python/python-mysql.html
python下MySQLdb使用.docx
python下MySQLdb使用.pdf
python2.6-MySQLdb,包括python2.6安装包、MySQLdb for python2.6安装包、MySQLdb使用配置,为想学习Python操作mysql数据库的同学提供了极大的方便。。。
主要介绍了windows下python之mysqldb模块安装方法,需要的朋友可以参考下
2021_w_.1.python 驱动MySQLdb(create_engine)代码
python下MySQLdb使用[归纳].pdf
Python-MySQLdb-examplePython-MySQLdb-example本文主要介绍通过MySQLdb实现Python对MySQL数据库的访问和操作。备注:execute 把一条查询语句发送给mysql服务器,这里有两种情况:CREATE、INSERT、DELETE、UPDATE、...
主要给大家介绍了在linux环境下python中MySQLdb模块的安装方法,文中给大家介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
课题-Python-MySQLdb-学习总结.docx
关于python的MySQldb模块的入库应用实例,将某文件夹下的文件解析后入库并删除原文件。