我正在使用virtualenv
,须要安装“ psycopg2”。 python
我已经完成如下工做: linux
pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
我有如下消息: sql
Downloading/unpacking http://pypi.python.org/packages/source/p/psycopg2/psycopg2 -2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160 Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded Running setup.py egg_info for package from http://pypi.python.org/packages/sou rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160 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'. Complete output from command python setup.py egg_info: running egg_info creating pip-egg-info\psycopg2.egg-info writing pip-egg-info\psycopg2.egg-info\PKG-INFO writing top-level names to pip-egg-info\psycopg2.egg-info\top_level.txt writing dependency_links to pip-egg-info\psycopg2.egg-info\dependency_links.txt writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt' warning: manifest_maker: standard file '-c' not found 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'. ---------------------------------------- Command python setup.py egg_info failed with error code 1 Storing complete log in C:\Documents and Settings\anlopes\Application Data\pip\p ip.log
个人问题是,我只须要这样作才能使psycopg2工做? bash
python setup.py build_ext --pg-config /path/to/pg_config build ...
我已经为此奋斗了好几天,终于找到了如何使“ pip install psycopg2”命令在Windows(运行Cygwin)的virtualenv中运行的方法。 post
我碰到了“找不到pg_config可执行文件”。 错误,但我已经在Windows中下载并安装了postgres。 它也安装在Cygwin中。 在Cygwin中运行“哪一个pg_config”给出了“ / usr / bin / pg_config”,而运行“ pg_config”给出了合理的输出-可是,与Cygwin一块儿安装的版本是: 网站
版本= PostgreSQL 8.2.11 ui
这不适用于当前版本的psycopg2,后者彷佛至少须要9.1。 当我在Windows路径中添加“ c:\\ Program Files \\ PostgreSQL \\ 9.2 \\ bin”时,Cygwin pip安装程序可以找到正确的PostgreSQL版本,而且可以使用pip成功安装该模块。 (不管如何,这可能比使用Cygwin版本的PostgreSQL更可取,由于本机版本运行得更快)。 spa
对于Python 3,您应该在Debian下使用sudo apt-get install libpq-dev python3-dev
。 postgresql
在CentOS上,您须要postgres开发软件包: code
sudo yum install python-devel postgresql-devel
至少这是CentOS 6上的解决方案。
除了安装必需的软件包外,我还须要手动将PostgreSQL bin目录添加到PATH。
$vi ~/.bash_profile
在export PATH
以前添加PATH=/usr/pgsql-9.2/bin:$PATH
export PATH
。
$source ~/.bash_profile
$pip install psycopg2
我使用PG下载网站http://www.postgresql.org/download/linux/redhat/上的RedHat / CentOS存储库安装了Postgresql92 。
要获取pg_config,我必须将/usr/pgsql-9.2/bin添加到PATH。