Linux下编译安装MySQL-Python教程
1、下载mysql-python
官网地址:http://sourceforge.net/projects/mysql-python/
2、安装mysql-python
代码如下:
# tar -zxvf MySQL-python-1.2.3.tar.gz # cd MySQL-python-1.2.3 # whereis mysql_config mysql_config: /usr/bin/mysql_config /usr/share/man/man1/mysql_config.1.gz # vi site.cfg threadsafe = False mysql_config = /usr/bin/mysql_config # whereis mysql mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz # export LD_LIBRARY_PATH=/usr/include/mysql # python setup.py build # python setup.py install
注意:
1.编译mysql-python需要mysql头文件。
2.安装mysql-python需要setuptools工具。
3、测试
代码如下:
# python >>> import MySQLdb >>>
如果没有错误提示或者以下错误提示,那么表示安装成功。
错误提示:
代码如下:
/usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.pyc, but /root/MySQL-python-1.2.3 is being added to sys.path
报错原因:
执行python setup.py install,MySQLdb模块会被拷贝python的site-packages目录。如果在执行python的目录中存在相同的模块,就可能重复导入模块。
解决办法:
换个目录执行python即可。
相关推荐
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11
世樹 2020-11-11