Mac python中安装psycopg2

上一篇 / 下一篇  2018-07-03 10:56:06

最近在学习python,学到python链接数据库,因为公司目前的

系统使用的是postgresql,为了能使用python链接上数据库,

需要安装API psycopg2。

下载psycopg2,直接在官网下载,地址:http://initd.org/psycopg/

解压psycopg2-2.7.3.tar.gz  命令:tar -zxvf psycopg2-2.7.3.tar.gz

解压完成之后,执行,python setup.py build,报错:
 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'.

我的解决方案:


 1.打开setup.cfg,发现是没有配置pg_config文件的目录

2.在这个目录下

/Library/PostgreSQL/9.3/bin下找到pg_config文件


3.配置目录:

vi setup.config


修改

pg_config =/Library/PostgreSQL/9.3/bin/pg_config


保存


4.删除  build目录之后,再次执行:python setup.py build,不报错,成功


5.最后再执行:sudo python setup.py install


安装成功


TAG:

 

评分:0

我来说两句

Open Toolbar