如何在Python上安装带有“pip”的psycopg2?

2024-03-28 14:09:52 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我的问题是,我只需要这样做就可以让心理医生工作?

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

Tags: pipthetopathpybuildinfoconfig
3条回答

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

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

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

sudo yum install python-devel postgresql-devel

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

您需要同时安装PostgresSQL和Python开发包,否则psycopg2安装将失败。

为下面提到的操作系统运行命令,然后再次尝试安装psycopg2。

操作系统/发行版

Debian/Ubuntu公司

Python2

sudo apt install libpq-dev python-dev

Python3

sudo apt install libpq-dev python3-dev

CentOS 6号

Banjer's answer


如果这还不够,试试

sudo apt install build-essential

或者

sudo apt install postgresql-server-dev-all

在再次安装psycopg2之前。

相关问题 更多 >