在Mac OS X上安装libpq-dev

tch*_*ore 13 python django postgresql psycopg2

我正在尝试在我的本地Mac OS X上运行带有Postgresql后端的Django.我已经使用pip安装了Django:

sudo pip install Django
Run Code Online (Sandbox Code Playgroud)

我已经安装PostgreSQL用于二进制安装程序之一在这里.

但是当我尝试安装psycopg2时,我得到一个错误(粘贴在下面),它找不到pg_config.

这个问题看来我应该安装,libpq-dev但我不确定如何.

我尝试libpqxx使用MacPorts 安装,但是没有做任何事情.

如何安装libpg-dev?或者还有其他我想念的东西?

henrietta:~ $ pip install psycopg2
Downloading/unpacking psycopg2
  Downloading psycopg2-2.4.5.tar.gz (719Kb): 719Kb downloaded
  Running setup.py egg_info for package psycopg2
    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 /Users/thomas/.pip/pip.log
Run Code Online (Sandbox Code Playgroud)

esi*_*ver 20

对于OSX 10.9.2 Mavericks来说,这对我有用.尝试先用brew安装postgres:

brew install postgresql
Run Code Online (Sandbox Code Playgroud)

然后安装pg

gem install pg
Run Code Online (Sandbox Code Playgroud)

  • 我不得不做`brew链接postgresql@9.4 --force`,以便gem可以找到`pg_config`二进制文件 (2认同)

tch*_*ore 14

所以我最终遵循这里的建议:

http://blog.jonypawks.net/2008/06/20/installing-psycopg2-on-os-x/

结果我确实pg-config安装了,但我不得不四处寻找它.一旦我把它包括在路径中,一切都在游泳.这是该链接的片段:

PATH=$PATH:/Library/PostgresPlus/8.3/bin/ sudo easy_install psycopg2
Run Code Online (Sandbox Code Playgroud)

我使用pip而不是easy_install和我的PostgreSQL安装目录略有不同,但这是要点.

  • 使用Postgres.app更新OSX Mav 9.3.2.0 RC2`sudo PATH = $ PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2` (6认同)
  • 使用Postgres更新OSX Mav 9.3`PATH = $ PATH:/Library/PostgreSQL/9.3/bin/ pip install psycopg2` (3认同)
  • 这对我来说是A-OK.OSX Maverick与Postgres.app 9.2.2.0:PATH = $ PATH:/Applications/Postgres.app/Contents/MacOS/bin pip install psycopg2 (2认同)

kgr*_*kgr 4

只需从源代码安装 postgres 即可。我在 Mac OS X 上这样做。它很简单:

./configure 
make
sudo make install
Run Code Online (Sandbox Code Playgroud)

当然,您可能需要额外的步骤,例如自动启动或设置配置选项,但我相信这仍然是 Mac OS X 上最轻松的设置方法。

如果您出于某种原因想避免从源代码安装,您应该寻找 psycopg2 的二进制版本,例如: http: //www.initd.org/psycopg/download/

sudo port install py27-psycopg2
Run Code Online (Sandbox Code Playgroud)