Linux下编译安装MySQL-Python教程

WBOY
Release: 2016-06-10 15:18:10
Original
1125 people have browsed it

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即可。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template