【问题标题】:pip install requirements failing with exit code 1 [duplicate]pip 安装要求失败,退出代码为 1 [重复]
【发布时间】:2021-07-12 05:05:11
【问题描述】:

当我尝试使用pip install -r requirements.txt 安装项目的要求时 它一直失败并显示以下输出。

[sarthak@envy cyc1eon]$ pip install -r requirements.txt
Defaulting to user installation because normal site-packages is not writeable
Collecting asgiref==3.2.10
  Downloading asgiref-3.2.10-py3-none-any.whl (19 kB)
Collecting dj-database-url==0.5.0
  Downloading dj_database_url-0.5.0-py2.py3-none-any.whl (5.5 kB)
Collecting Django==3.0.8
  Downloading Django-3.0.8-py3-none-any.whl (7.5 MB)
     |████████████████████████████████| 7.5 MB 2.6 MB/s 
Collecting django-heroku==0.3.1
  Downloading django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB)
Collecting gunicorn==20.0.4
  Downloading gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
     |████████████████████████████████| 77 kB 5.5 MB/s 
Requirement already satisfied: setuptools>=3.0 in /usr/lib/python3.9/site-packages (from gunicorn==20.0.4->-r requirements.txt (line 5)) (54.2.0)
Collecting psycopg2==2.8.5
  Downloading psycopg2-2.8.5.tar.gz (380 kB)
     |████████████████████████████████| 380 kB 9.7 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lc8h8hyn/psycopg2_4a4c96a147204fd489df1a2f7201063a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lc8h8hyn/psycopg2_4a4c96a147204fd489df1a2f7201063a/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-pip-egg-info-ztzh9r6w
         cwd: /tmp/pip-install-lc8h8hyn/psycopg2_4a4c96a147204fd489df1a2f7201063a/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-pip-egg-info-ztzh9r6w/psycopg2.egg-info
    writing /tmp/pip-pip-egg-info-ztzh9r6w/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-pip-egg-info-ztzh9r6w/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-pip-egg-info-ztzh9r6w/psycopg2.egg-info/top_level.txt
    writing manifest file '/tmp/pip-pip-egg-info-ztzh9r6w/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.

项目的要求是

asgiref==3.2.10
dj-database-url==0.5.0
Django==3.0.8
django-heroku==0.3.1
gunicorn==20.0.4
psycopg2==2.8.5
psycopg2-binary==2.8.5
python-decouple==3.3
pytz==2020.1
sqlparse==0.3.1
whitenoise==5.1.0

【问题讨论】:

标签: python pip requirements.txt


【解决方案1】:

错误消息很清楚 - 缺少 pg-config,因此无法从源代码构建。从源代码构建的替代方法是使用psycorg2-binary - 已经存在于requirements.txt 中并在错误消息本身中提出:

如果您不想从源代码构建 psycopg2,请安装 PyPI 'psycopg2-binary' 包代替

只需从requirements.txt 中删除psycopg2==2.8.5

或者检查pg_config executable not found

【讨论】:

    【解决方案2】:

    尝试替换:

    asgiref==3.2.10
    dj-database-url==0.5.0
    Django==3.0.8
    django-heroku==0.3.1
    gunicorn==20.0.4
    psycopg2==2.8.5
    psycopg2-binary==2.8.5
    python-decouple==3.3
    pytz==2020.1
    sqlparse==0.3.1
    whitenoise==5.1.0
    

    在 requirements.txt 中:

    asgiref
    dj-database-url
    Django
    django-heroku
    gunicorn
    psycopg2
    psycopg2-binary
    python-decouple
    pytz
    sqlparse
    whitenoise
    

    【讨论】:

    • 这有什么帮助?
    • @buran 很好,因为他遇到了psycopg2-2.8.5 的问题,我想也许 2-2.8.5 是旧版本。你永远不知道
    • 好吧,错误信息很清楚 - 缺少 pg-config,因此无法从源代码构建。从源代码构建的替代方法是使用psycorg2-binary - 已经存在于requirments.txt 中。通常在指定时删除包版本是个坏主意,并且可能导致更大的问题 - 例如不兼容等
    • 试过了,没用。
    • @buran 他的程序需要那个模块才能工作吗?
    猜你喜欢
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 2021-06-01
    • 2012-01-11
    • 2016-04-18
    • 1970-01-01
    • 2021-03-01
    相关资源
    最近更新 更多