首页 > 新闻动态 >  

新闻动态
NEWS

python中应用postgres

添加时间:2013-5-5 点击量:

本文不具体介绍如何用python连接并操纵postgres数据库,只介绍如安在Python下安装postgres数据库接口,以及在安装过程中碰到的一些题目。


我此中博客介绍了哄骗easy_install来安装mysql数据库接口。若是没有安装easy_install的童鞋,请参考博文: Ubuntu下安装easy_install 和 mysql-python。


和Mysql一样,用Python连接postgres数据库也须要对应的连接库。我采取的是psycopg2 ,若是有童鞋不想用easy_install安装,上方已经给出了psycopg2的官方网址,里面也介绍了其他的安装办法以及具体的应用文档。下面开端介绍哄骗easy_install安装psycopg2的过程:


注:以下过程是在64位Ubuntu12.04机械上实验的,32位体系应当也实用,体系未安装postgres数据库,默认已经安装了easy_install。



sudo easy_install psycopg2


在没有安装postgres开辟景象的机械上很可能呈现下面的错误



Error: pg_config executable not found.


Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:

python setup.py build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in setup.cfg.
error: Setup script exited with
1


提示说,pg_config executable没有找到,google一下,发明须要别的安装一个postgres的开辟库(我是这么懂得的~)



sudo apt-get install libpq-dev


安装完成后,再次安装 psycopg2,postgres for python的开辟景象就已经设备好了,在开辟中若是想连接postgres数据库,直接import psycopg2即可,关于psycopg2的具体应用办法可接见我上方供给的网址


本文来自博客园,若是查看原文请点击 http://www.cnblogs.com/meibenjin/archive/2013/05/05/3061147.html


原来,再大的房子,再大的床,没有相爱的人陪伴,都只是冰冷的物质。而如果身边有爱人陪伴,即使房子小,床小,也觉得无关紧要,因为这些物质上面有了爱的温度,成了家的元素。—— 何珞《婚房》#书摘#
分享到: