【问题标题】:Error Code 1 when trying to "pip install psycopg2" in Max OSX Yosemite尝试在 Mac OS Yosemite 中“pip install psycopg2”时出现错误代码 1
【发布时间】:2014-12-30 10:49:11
【问题描述】:

我正在尝试在我的 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 中添加一个目录?但是,我无法在网上找到任何可以帮助我这样做的东西。如果有人以逐步的方式对此有答案,将不胜感激。谢谢。

【问题讨论】:

    标签: macos postgresql pip psycopg2 osx-yosemite


    【解决方案1】:

    如果你运行这样的错误,那么你需要安装两个包。

        sudo apt-get install libpq-dev python-dev
    

    现在安装 psycopg2

        pip install psycopg2
    

    【讨论】:

    • 在 python 3 上,需要python3-dev
    【解决方案2】:

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

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

    您的版本取决于您安装的内容。将此添加到 .bash_profile 中的 $PATH 变量中,重新加载它,瞧!

    【讨论】:

      【解决方案3】:

      pg_config 应该位于

      /Library/PostgreSQL/9.3/bin/pg_config

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

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

      【讨论】:

      • 很遗憾我不得不添加 PostgreSQL 来执行此操作,但是一旦我安装了它,将 PIP 升级为 SUDO,然后将路径添加到 /etc/paths 并重新登录,我可以 pip install psycopg2。
      【解决方案4】:

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

      which pg_config
      

      根据你安装 postgres 的方式,你应该得到一个类似于其中任何一个的路径

      /Library/PostgreSQL/9.3/bin/pg_config
      

      /usr/local/bin/pg_config
      

      像这样将包含 pg_config 可执行文件的目录添加到 PATH 环境变量中

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

      export PATH="/usr/local/bin:$PATH"
      

      如果命令which pg_config 没有返回任何内容,那么你应该先运行安装postgres

      brew install postgres
      

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

      【讨论】:

        猜你喜欢
        • 2013-06-25
        • 2020-12-11
        • 2019-11-11
        • 2015-12-27
        • 2018-07-13
        • 1970-01-01
        • 2018-12-24
        • 2019-11-06
        • 1970-01-01
        相关资源
        最近更新 更多