在Ubuntu中使用pip安装psycopg2时出错

时间:2019-12-05 07:38:28

标签: python psycopg2

我已经使用conda激活了venv

$ source激活/ home / sim / anaconda3 / envs / myenv

我在(myenv) sim@ma-Vostro-15-3568:~/flask/venv$行事中

python3 -m pip install psycopg2

我也尝试过pip3

python --version是3.6

错误在下面

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

ERROR: Command errored out with exit status 1:
     command: /home/mak/anaconda3/envs/myenv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7ql73mks/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7ql73mks/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 /tmp/pip-install-7ql73mks/psycopg2/pip-egg-info
         cwd: /tmp/pip-install-7ql73mks/psycopg2/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-install-7ql73mks/psycopg2/pip-egg-info/psycopg2.egg-info
    writing /tmp/pip-install-7ql73mks/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-install-7ql73mks/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-install-7ql73mks/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file '/tmp/pip-install-7ql73mks/psycopg2/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
    <http://initd.org/psycopg/docs/install.html>).

2 个答案:

答案 0 :(得分:0)

尝试一下

sudo apt install libpq-dev python3-dev

LINK获得帮助

答案 1 :(得分:0)

根据错误消息,您可以1.指定路径,或2.使用以下命令安装psycopg2-binary:pip3 install psycopg2-binary