MySQL——Python接口配置
2015-09-05 17:04
489 查看
How to set-up MySQL for Python on Ubuntu
by David Winterbottom on Thursday, 5 January 2012Note, 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
相关文章推荐
- 利用Python通过telnet、ssh连接交换机、路由器等设备配置备份 第2版(粗略版)
- 测试比json更快更小的二进制数据传输格式Msgpack [pythono MessagePack 版本] - 峰云,就她了。 - 51CTO技术博客
- 分享一个分布式定时任务系统 ( python) - V2EX
- python 应用xml.dom.minidom读xml
- python 安装包error: Unable to find vcvarsall.bat
- 卸载使用“python setup.py install”安装的包
- python 递归遍历文件夹
- Python-selenium进阶操作
- python第二天 - 异常处理
- 使用python绘制4个相切的圆形
- Python Wheel (.whl)文件安装实践
- 用Python制作新浪微博爬虫
- 零基础学python-11.3 代码分隔符
- 零基础学python-11.3 代码分隔符
- 当Python和R遇上北京二手房(下)
- 2015/9/4 Python基础(8):映射和集合类型
- 2小时玩转python基础(上)
- mac多版本python安装 pymysql
- 零基础学python-11.2 python语法规则
- 零基础学python-11.2 python语法规则