码迷,mamicode.com
首页 > 数据库 > 详细

mysql-python 安装

时间:2017-08-07 00:25:38      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:位置   1.2   mod   stdin   erro   stat   config   setup   软件包   

[root@localhost ~]# [root@localhost ~]# [root@localhost ~]# gcc -v    查看是否安装gcc 若报错则未安装

[root@localhost ~]# yum -y install gcc    安装gcc

[root@localhost ~]# wget http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.4b4/MySQL-python-1.2.4b4.tar.gz?use_mirror=ncu             下载软件包

 [root@localhost ~]# tar zxvf MySQL-python-1.2.4b4.tar.gz cd MySQL-python-1.2.4b4        解压软件包

解压包复制到 /usr/local/src/ 下

进入 /usr/local/src/MySQL-python-1.2.4b4

[root@localhost MySQL-python-1.2.4b4]# find / -name mysql_config     查看  mysql_config   文件位置
/usr/local/mysql/bin/mysql_config
 
[root@localhost ~]# vim site.cfg   进入site.cfg  配置文件进行修改
 

# embedded: link against the embedded server library # threadsafe: use the threadsafe client # static: link against a static library (probably required for embedded)

embedded = False

threadsafe = False  (改为False)

static = False

# 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/mysql/bin/mysql_config    (前面的#去掉,并把路径更改正确)

 

最后进行安装:

# python setup.py build
# python setup.py install
完毕之后 进入python
>>> import MySQLdb
若出错:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory
 
根据最后提示,应该是找不着一个交libmysqlclient.so.20的文件,于是到mysql安装目录里找到这个文件并且做一个软连接到/usr/lib
[root@localhost lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib/libmysqlclient.so.20
 
再次导入模块就成功了
 
 
 

 

mysql-python 安装

标签:位置   1.2   mod   stdin   erro   stat   config   setup   软件包   

原文地址:http://www.cnblogs.com/luckycn/p/7296238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!