linux mysql.py_linux下 python MySQLdb模块安装

1.下载:MySQL-python

http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3b1/MySQL-python-1.2.3b1.tar.gz/download

tar -zxf MySQL-python-1.2.3b1.tar.gz

cd MySQL-python-1.2.3b1

python setup.py build

==>ImportError: No module named setuptools

2.下载setuptools

http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c8.tar.gz

tar -zxf setuptools-0.6c8.tar.gz

cd setuptools-0.6c8

python setup.py build

python setup.py install

3.回到MySQL-python-1.2.3b目录

cd MySQL-python-1.2.3b1

在运行时python setup.py build && python setup.py install没有如下错误:

有类似错误,处理方式如下:

python setup.py build #若,报错:mysql_config not found

找出mysql 安装目录:/opt/mysql/

vi MySQL-python-1.2.3b1/setup_posix.py

行     26 #mysql_config.path = "mysql_config"

改成如下:

行     27 mysql_config.path = "/opt/mysql/bin/mysql_config"

再次运行

python setup.py build #报错:/usr/bin/ld:cannot find -lmysqlclient_r

root下:

echo "/opt/mysql/lib/mysql" >> /etc/ld.so.conf #请主意这个/etc/ld.so.conf,

这个是ld的默认配置文件,视系统不同而不同。 /opt/mysql/lib/mysql与mysql安装目录相关。

刷新ld配置文件让其生效,使用:ldconfig

接着运行 python setup.py install

检验是否已经安装成功MySQLdb时,提示如下错误:

>>> import MySQLdb

/usr/lib/python2.4/site-packages/MySQL_python-1.2.3b1-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3b1-py2.4-linux-i686.egg/_mysql.pyc, but /data/MySQL-python-1.2.3b1 is being added to sys.path

Traceback (most recent call last):

File "", line 1, in ?

File "MySQLdb/__init__.py", line 19, in ?

import _mysql

File "build/bdist.linux-i686/egg/_mysql.py", line 7, in ?

File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__

ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory

解决方法:

vi /etc/profile下加:

export LD_LIBRARY_PATH=/opt/mysql/lib/mysql:$LD_LIBRARY_PATH

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值