您现在的位置是: 网站首页> 学习笔记> 系统相关 系统相关

centos使用pip安装psycopg2时报错

2024-01-19 [python] 2285人已围观

今天在宝塔上部署django程序,程序使用了PGSQL,需要安装psycopg2库, 安装时报错,错误如下:

Using cached https://mirrors.aliyun.com/pypi/packages/c9/5e/dc6acaf46d78979d6b03458b7a1618a68e152a6776fce95daac5e0f0301b/psycopg2-2.9.9.tar.gz (384 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
   exit code: 1
  ╰─> [25 lines of output]
      /www/server/pyporject_evn/hotword_venv/lib/python3.10/site-packages/setuptools/dist.py:697: UserWarning: Usage of dash-separated 'index-url' will not be supported in future versions. Please use the underscore name 'index_url' instead
        warnings.warn(
      running egg_info
      creating /tmp/pip-pip-egg-info-7yecr9zv/psycopg2.egg-info
      writing /tmp/pip-pip-egg-info-7yecr9zv/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /tmp/pip-pip-egg-info-7yecr9zv/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /tmp/pip-pip-egg-info-7yecr9zv/psycopg2.egg-info/top_level.txt
      writing manifest file '/tmp/pip-pip-egg-info-7yecr9zv/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.
[root@VM-4-17-centos hotword]# vim requirements.txt 
[root@VM-4-17-centos hotword]# pip3 install -r requirements.txt 
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting APScheduler==3.10.4 (from -r requirements.txt (line 1))
  Using cached https://mirrors.aliyun.com/pypi/packages/13/b5/7af0cb920a476dccd612fbc9a21a3745fb29b1fcd74636078db8f7ba294c/APScheduler-3.10.4-py3-none-any.whl (59 kB)
Collecting asgiref==3.7.2 (from -r requirements.txt (line 2))
  Using cached https://mirrors.aliyun.com/pypi/packages/9b/80/b9051a4a07ad231558fcd8ffc89232711b4e618c15cb7a392a17384bbeef/asgiref-3.7.2-py3-none-any.whl (24 kB)
Collecting async-timeout==4.0.3 (from -r requirements.txt (line 3))
  Using cached https://mirrors.aliyun.com/pypi/packages/a7/fa/e01228c2938de91d47b307831c62ab9e4001e747789d0b05baf779a6488c/async_timeout-4.0.3-py3-none-any.whl (5.7 kB)
Collecting cffi==1.16.0 (from -r requirements.txt (line 4))
  Using cached https://mirrors.aliyun.com/pypi/packages/c9/7c/43d81bdd5a915923c3bad5bb4bff401ea00ccc8e28433fb6083d2e3bf58e/cffi-1.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (443 kB)
Collecting curl-cffi==0.5.10 (from -r requirements.txt (line 5))
  Using cached https://mirrors.aliyun.com/pypi/packages/93/04/0d57a51690451437f72563031036ea4f4b529bc0cfd8e8d93487075cbe80/curl_cffi-0.5.10-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.2 MB)
Collecting Django==5.0.1 (from -r requirements.txt (line 6))
  Using cached https://mirrors.aliyun.com/pypi/packages/97/67/6804ff6fc4fa6df188924412601cc418ddc2d0a500963b0801a97b7ec08a/Django-5.0.1-py3-none-any.whl (8.1 MB)
Collecting django-redis==5.4.0 (from -r requirements.txt (line 7))
  Using cached https://mirrors.aliyun.com/pypi/packages/b7/f1/63caad7c9222c26a62082f4f777de26389233b7574629996098bf6d25a4d/django_redis-5.4.0-py3-none-any.whl (31 kB)
Collecting psycopg==3.1.17 (from -r requirements.txt (line 8))
  Using cached https://mirrors.aliyun.com/pypi/packages/fe/f2/ab7de9bed559fa1f5efe2b9638be6e2d51ae605c9c5a321e26290cfe9899/psycopg-3.1.17-py3-none-any.whl (178 kB)
Collecting psycopg2 (from -r requirements.txt (line 9))
  Using cached https://mirrors.aliyun.com/pypi/packages/c9/5e/dc6acaf46d78979d6b03458b7a1618a68e152a6776fce95daac5e0f0301b/psycopg2-2.9.9.tar.gz (384 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
   exit code: 1
  ╰─> [25 lines of output]
      /www/server/pyporject_evn/hotword_venv/lib/python3.10/site-packages/setuptools/dist.py:697: UserWarning: Usage of dash-separated 'index-url' will not be supported in future versions. Please use the underscore name 'index_url' instead
        warnings.warn(
      running egg_info
      creating /tmp/pip-pip-egg-info-8j7xvza3/psycopg2.egg-info
      writing /tmp/pip-pip-egg-info-8j7xvza3/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /tmp/pip-pip-egg-info-8j7xvza3/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /tmp/pip-pip-egg-info-8j7xvza3/psycopg2.egg-info/top_level.txt
      writing manifest file '/tmp/pip-pip-egg-info-8j7xvza3/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.

出现这个问题主要还是环境问题。

解决办法:

yum install postgresql-devel

文章评论

暂无评论

添加评论





本栏推荐

站点信息

  • 建站时间:2021-01-01
  • 网站程序:Django 3.1.2
  • 文章统计:53篇
  • 文章评论:36条
  • 统计数据