我正在使用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。