尝试点子安装psycopg2 == 2.7时出错

时间:2020-08-22 14:47:05

标签: django macos pycharm psycopg2 heroku-cli

我正在尝试在我的PyCharm终端上运行pip install psycopg2==2.7.*软件包,以便我可以部署我的网站,但是却收到下面显示的消息

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.

2 个答案:

答案 0 :(得分:1)

如果您使用的是Linux,则需要安装PostgreSQL才能运行数据库,然后将客户端连接到PostgreSQL数据库,您将需要其他软件包,例如 libpq-dev libpq5

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

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

答案 1 :(得分:0)

因此,如果您使用的是Mac,我可以考虑两种方式:

  • pip安装psycopg2-binary
  • 使用brew或优秀的postgre.app安装PostgreSQL,并将路径指向pg_config二进制文件(这实际上是您得到的错误)