当前位置: 首页 > 知识库问答 >
问题:

使用pip[duplicate]安装psycopg2时出错

吴浩皛
2023-03-14

我尝试使用这个命令< code>docker build -t myimage在django中运行docker。现在docker文件尝试运行< code > RUN pip install-r/app/requirements . txt-no-cache-dir ,但是当ot到达< code >下载psycopg2-2.9.3.tar.gz(380 kB)部分时,它会抛出错误。

注意:我的requirements.txt文件中没有psycopg2,只有< code>psycopg2-binary。

requirements.txt文件

...
dj-database-url==0.5.0
Django==3.2.7
django-filter==21.1
django-formset-js-improved==0.5.0.2
django-heroku==0.3.1
psycopg2-binary
python-decouple==3.5
...

  Downloading pytz-2022.2.1-py2.py3-none-any.whl (500 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 500.6/500.6 kB 2.6 MB/s eta 0:00:00
Collecting psycopg2
  Downloading psycopg2-2.9.3.tar.gz (380 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 380.6/380.6 kB 2.7 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      running egg_info
      creating /tmp/pip-pip-egg-info-383i9hb2/psycopg2.egg-info
      writing /tmp/pip-pip-egg-info-383i9hb2/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /tmp/pip-pip-egg-info-383i9hb2/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /tmp/pip-pip-egg-info-383i9hb2/psycopg2.egg-info/top_level.txt
      writing manifest file '/tmp/pip-pip-egg-info-383i9hb2/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>).

      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
The command '/bin/sh -c pip install -r /app/requirements.txt --no-cache-dir' returned a non-zero code: 1

Dockerfile

FROM python:3.8.13-slim-buster
WORKDIR /app
COPY ./my_app ./

RUN pip install --upgrade pip --no-cache-dir

RUN pip install -r /app/requirements.txt --no-cache-dir

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
# CMD ["gunicorn", "main_app.wsgi:application", "--bind"]

共有1个答案

巫马星雨
2023-03-14

如果要使用 psycopg2,则需要安装系统依赖项 (pg_*),否则,您可以通过 psycopg2-binary 重新放置 psycopg2 来使用包含它们的一体化软件包

 类似资料:
  • 问题内容: 不知道这里发生了什么,但是每次尝试使用pip安装某些东西时,我都会收到一个错误: 命令“ / usr / bin / python -c”导入设置工具,标记化; file =’/ private / var / folders / b0 / 5843zgyj1yz3b8q2l7wrtj8h0000gn / T / pip-build-V4hy8S / PySocks / setup.p

  • 在尝试了我可以找到的关于这个问题的帖子中提到的所有内容后,我还没有安装psycopg2 警告:MANIFEST_MAKER:找不到标准文件“-C”

  • 我试图在Windows7中为Python3.4安装一个图表工具(Matplotlib-V1.4.2),但到目前为止,我的所有尝试似乎都无法完成这一工作。 尝试: 我已从GitHub下载了pip -不使用 这里有一个类似的问题,我也尝试了这些建议,但我得到了以下错误 我肯定我错过了什么,你的一步一步的指导在这方面将非常感谢。

  • 问题内容: 我在Mac系统上做了一个简单的操作。它安装正确,但是当我尝试使用psycopg2时出现错误: 显示恰到好处。我已经在多个virtualenvs上安装了psycopg2,但这是我第一次看到这样的错误。我尝试卸载并重新安装,结果相同。请帮忙 问题答案: 升级到Mountain Lion后,我遇到了类似的问题。 确保不要按Slack的建议复制libssl。*文件,而是确保它实际上是到库的最新

  • 在命令提示符下通过pip installer for Python3.7安装pandas时,我反复遇到以下错误 我已经通过管理员运行了该命令,但它没有运行。

  • 我试图在命令shell上使用安装,但出现以下错误: 使用缓存收集rpy2https://files.pythonhosted.org/packages/c7/43/401afad8556bf92b08bd7d422cacac614b0e8dd2bce31848318bbcb18f48/rpy2-3.0.5.tar.gz错误:从命令python安装程序完成输出。py egg_info:ERROR:T