mysql python接口配置文件_MySQL——Python接口配置

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 "", line 14, in

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

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 "", line 14, in

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值