如何在Python上使用“pip”安装psycopg2?

我使用的是virtualenv ,我需要安装“psycopg2”。

我做了以下工作:

pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160

我有以下信息:

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-infopsycopg2.egg-info

writing pip-egg-infopsycopg2.egg-infoPKG-INFO

writing top-level names to pip-egg-infopsycopg2.egg-infotop_level.txt

writing dependency_links to pip-egg-infopsycopg2.egg-infodependency_links.txt

writing manifest file 'pip-egg-infopsycopg2.egg-infoSOURCES.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 SettingsanlopesApplication Datapipp
ip.log

我的问题,我只需要做到这一点,让psycopg2工作?

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

我发现这篇文章正在寻找针对这个问题的Linux解决方案。

“goshawk”这篇文章给了我解决方案:如果你在Ubuntu / Debian上,运行sudo apt-get install libpq-dev python-dev

更新

由于更多人发现这个答案很有用,并发布了他们自己的解决方案,下面列出了他们的解决方案:

于Debian / Ubuntu

Python 2

sudo apt install libpq-dev python-dev

Python 3

sudo apt install libpq-dev python3-dev

额外

如果以上都不能解决您的问题,请尝试

sudo apt install build-essential

要么

sudo apt install postgresql-server-dev-all

在CentOS上,你需要postgres开发包:

sudo yum install python-devel postgresql-devel

至少这是CentOS 6上的解决方案。


在使用Postgres.app版本9.3.2.0 RC2的Mac Mavericks中安装Postgres后,我需要使用以下代码:

sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2

链接地址: http://www.djcxy.com/p/60839.html

上一篇: How to install psycopg2 with "pip" on Python?

下一篇: Mysql : invisible characters