您的位置:首页 > 编程语言 > Python开发

MySQL——Python接口配置

2015-09-05 17:04 489 查看

How to set-up MySQL for Python on Ubuntu

by David Winterbottom on Thursday, 5 January 2012

Note, this article was published over 3 years ago and hence the content may be stale. Consume with a pinch of salt.

This is just for my own reference as I always forget the dependencies for setting up MySQL on a new machine.

Installation:

Starting with a vanilla Lucid install [1], install pip and upgrade to the latest version:

apt-get install python-pip
pip install -U pip


Next, install the required development packages:

apt-get install python-dev libmysqlclient-dev


then

pip install MySQL-python


should complete successfully.

[1] Tested using the Lucid32 Vagrant box: http://files.vagrantup.com/lucid32.box

Symptoms of missing headers

Without libmysqlclient-dev, you’ll see something like this:

Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/vagrant/build/MySQL-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: not found

Traceback (most recent call last):

File "<string>", line 14, in <module>

File "/home/vagrant/build/MySQL-python/setup.py", line 15, in <module>

metadata, options = get_config()

File "setup_posix.py", line 43, in get_config

libs = mysql_config("libs_r")

File "setup_posix.py", line 24, in mysql_config

raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found


Without python-dev, you’ll see something that ends with the following:

...

_mysql.c:2620: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_mysql_ResultObject_Type'

_mysql.c:2706: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_mysql_methods'

_mysql.c:2778: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token

_mysql.c:2810: warning: return type defaults to 'int'

_mysql.c: In function 'DL_EXPORT':

_mysql.c:2810: error: expected declaration specifiers before 'init_mysql'

_mysql.c:2888: error: expected '{' at end of input

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/home/vagrant/build/MySQL-python/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-dPF1DK-record/install-record.txt failed with error code 1
Storing complete log in /home/vagrant/.pip/pip.log


转自:How to set-up MySQL for Python on Ubuntu
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: