首页 > 解决方案 > 尝试 pip install psycopg2==2.7 时出错。*

问题描述

我正在尝试pip install psycopg2==2.7.*在我的 PyCharm 终端上运行该程序包,以便我可以部署我的站点,但我收到了下面显示的消息

Collecting psycopg2
  Using cached https://files.pythonhosted.org/packages/a8/8f/1c5690eebf148d1d1554fc00ccf9101e134636553dbb75bdfef4f85d7647/psycopg2-2.8.5.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /Users/applecare/PycharmProjects/learning_log/11_env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/w6/sqx_mjh176x08sjppl82f1l80000gn/T/pip-install-8j8wbzsu/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/w6/sqx_mjh176x08sjppl82f1l80000gn/T/pip-install-8j8wbzsu/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /private/var/folders/w6/sqx_mjh176x08sjppl82f1l80000gn/T/pip-install-8j8wbzsu/psycopg2/
    Complete output (23 lines):
    running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    
    Error: pg_config executable not found.
    
    pg_config is required to build psycopg2 from source.  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'.
    
    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 19.2.3, however version 20.2.2 is available.
You should consider upgrading via the '`pip install --upgrade pip`' command.

标签: djangomacospycharmpsycopg2heroku-cli

解决方案


如果你在 Linux 上,你需要安装 PostgreSQL 来运行你的数据库,然后将客户端连接到你的 PostgreSQL 数据库,你需要其他包,比如libpq-devlibpq5

您可以使用以下命令安装上述软件包。

sudo apt-get install postgresql
sudo apt-get install libpq5
sudo apt-get install libpq-dev

推荐阅读