Macos 尝试“打开”时出现错误代码1;pip安装psycopg2“;在Max OSX Yosemite

Macos 尝试“打开”时出现错误代码1;pip安装psycopg2“;在Max OSX Yosemite,macos,postgresql,pip,psycopg2,osx-yosemite,Macos,Postgresql,Pip,Psycopg2,Osx Yosemite,我试图在Django项目中使用postgresql,所以我一直在尝试安装psycopg2,但我一直遇到问题。因为我使用的是virtualenv,所以通过macports安装psycopg2没有帮助。我需要找到某种方法将其安装为虚拟环境中的应用程序 以下是我在我的virtualenv中尝试pip安装它时遇到的错误: Downloading/unpacking psycopg2 Downloading psycopg2-2.5.4.tar.gz (682kB): 682kB downloaded R

我试图在Django项目中使用postgresql,所以我一直在尝试安装psycopg2,但我一直遇到问题。因为我使用的是virtualenv,所以通过macports安装psycopg2没有帮助。我需要找到某种方法将其安装为虚拟环境中的应用程序

以下是我在我的virtualenv中尝试pip安装它时遇到的错误:

Downloading/unpacking psycopg2
Downloading psycopg2-2.5.4.tar.gz (682kB): 682kB downloaded
Running setup.py     (path:/Users/adfelix2/Documents/Hindsait_Work/Projects/nybc_pilot/build/psycopg2/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'.

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in         /Users/user/'privateinfo'/my_virtualenv/build/psycopg2
Storing debug log for failure in /Users/user/.pip/pip.log

好像我需要在pg_config中添加一个目录?然而,我在网上找不到任何有助于我这样做的东西。如果有人能一步一步地回答这个问题,我们将不胜感激。谢谢。

pg\u config
应位于

/Library/PostgreSQL/9.3/bin/pg\u config

(替换您为9.3安装的Postgres的任何版本)


只需将该目录添加到您的
PATH
环境变量中,您就可以继续前进。

如果您安装了位于Mac菜单栏中的Postgres.app,您必须将路径指向应用程序包中的pg_config可执行文件。您可以通过访问

/Applications/Postgres.app/Contents/Versions/9.3/bin

您的版本将取决于您安装的内容。将它添加到.bash_配置文件中的$PATH变量中,重新加载它,瞧

如果运行这样的错误,则需要安装两个软件包

    sudo apt-get install libpq-dev python-dev
现在安装psycopg2

    pip install psycopg2

在终端中运行此命令,以获取
pg_config
可执行文件的位置

which pg_config
根据您安装postgres的方式,您应该获得类似于这两种方式之一的路径

/Library/PostgreSQL/9.3/bin/pg_config

将包含
pg_config
可执行文件的目录添加到PATH环境变量中,如下所示

export PATH="/Library/PostgreSQL/9.3/bin:$PATH"

如果命令
which pg_config
未返回任何内容,则应首先通过运行

brew install postgres

然后重复上面列出的步骤。

很遗憾,我不得不添加PostgreSQL来完成这项工作,但一旦我安装了它,将PIP升级为SUDO,然后将路径添加到/etc/path并重新登录,我就可以PIP安装psycopg2。在python 3上,需要
python3 dev
export PATH="/usr/local/bin:$PATH"
brew install postgres