20

我正在尝试在本地 Mac OS X 上使用 Postgresql 后端运行 Django。我使用 pip 安装了 Django:

sudo pip install Django

我在这里使用其中一个二进制安装程序安装了 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
4

6 回答 6

29

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

brew install postgresql

然后安装 pg

gem install pg
于 2014-04-04T17:03:42.047 回答
15

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

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

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

于 2012-04-13T17:10:03.613 回答
4

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

./configure 
make
sudo make install

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

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

sudo port install py27-psycopg2
于 2012-04-12T23:02:41.643 回答
2

在小牛队的 postgress.app 文件pg_config中,/Applications/Postgres.app/Contents/MacOS/bin/所以我以这种方式解决了问题:

sudo PATH=$PATH:/Applications/Postgres.app/Contents/MacOS/bin/ pip install psycopg2
于 2014-04-26T22:34:54.550 回答
0

如果您只是想安装psycopg2在 Mac 上运行 Django 或 Flask 等,请使用:

pip install psycopg2-binary

来自文档https://www.psycopg.org/docs/install.html

于 2021-06-02T20:48:01.770 回答
0

使用 macports,这对我有用:

sudo port install postgresql96
sudo port select --set postgresql postgresql96

我相信这会安装所有 postgres 客户端工具和库,而 macports 有一个单独的端口用于安装服务器,即postgresql96-server.

于 2020-11-10T00:46:23.570 回答