[置顶] 让turboGears支持MySQL -- 解决MySQL-python-1.2.2的安装问题

来源:互联网 发布:json用什么解析 编辑:程序博客网 时间:2024/06/05 02:57
今天在配置服务器环境时发现即使安装了MySQL-python-1.2.2.tar.gz,也用不了MySQLdb模块的问题,在网上灌水了好长时间才从一个国外的论坛找到了一些解决方案
但是可惜不是很全面,结合自己的实践终于解决了这个问题.现将过程记录备案.

真诚的希望国内的程序员以及站长在发帖时能够记录些真实可靠的信息,不要人云亦云,
因为你的疏忽会造成我们长时间的困惑... 谢谢大家

进入Python 后 输入以下命令
import MySQLdb

结果发现 出现如下错误:
libmysqlclient_r.so.10 文件不存在


怎么会缺少这个 链接库呢 手工做了一个软连接 /usr/lib/libmysqlclient_r.so.10 发现爆出[变量未定义错误]:
ImportError: /usr/local/lib/python252/site-packages/_mysql.so: undefined symbol: mysql_set_character_set


困扰了一上午,找了好多国内的网站,包括很拽的博客,都没有找到答案,国内真正的高手们,倡导开源就不要敝帚自珍啊,抱怨 o(∩_∩)o...

解决方案:

第一步:
从 MySQL-python 官网下载MySQL-python-1.2.2.tar.gz文件,解压缩后,进入其中
找到site.cfg文件,修改如下所示:
[options]# embedded: link against the embedded server library# threadsafe: use the threadsafe client# static: link against a static library (probably required for embedded)embedded = Falsethreadsafe = Truestatic = True[compiler]#mysql_root: /usr/local/mysqllibrary_dirs: /usr/local/mysql/lib #此处为你的mysql共享库目录include_dirs: /usr/local/mysql/include #此处为你的mysql头文件目录# libraries: mysqlclient# The path to mysql_config.# Only use this if mysql_config is not on your PATH, or you have some weird# setup that requires it.#mysql_config = /usr/local/bin/mysql_config# The Windows registry key for MySQL.# This has to be set for Windows builds to work.# Only change this if you have a different version.registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0


embedded = False 要设为False,否则编译时爆出不能找到mysqld.a错误

使用 python setup.py build 编译
使用 python setup.py install 安装

它会自动安装到Python目录下,无需手动

第二步 解决libmysqlclient_r.so.10的问题:
ln -s /usr/lib/mysql/libmysqlclient_r.so.10 /lib/libmysqlclient_r.so.10


注意将/usr/lib/mysql/libmysqlclient_r.so.10做一个软连接到/lib目录

此时 在Python中导入成功 , 测试成功
0 0
原创粉丝点击