【问题标题】:Can not install psycopg2 on Mac 12.3, I keep getting this error无法在 Mac 12.3 上安装 psycopg2,我不断收到此错误
【发布时间】:2022-07-20 14:57:19
【问题描述】:

我最近买了一台 MacBook Pro,并正在为一些 python 和 Django 编程设置它,但我最终在安装 psycopg2 时遇到了问题,我已经尝试了几件事,但没有一个对我有用,这里留下了错误,

Collecting psycopg2
  Using cached psycopg2-2.9.3.tar.gz (380 kB)
  Preparing metadata (setup.py) ... 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 /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info
      writing /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/top_level.txt
      writing manifest file '/private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/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.

这表明 pip 不是问题,但 setup.py 却找不到任何东西,

欢迎任何帮助

谢谢

【问题讨论】:

  • 您阅读了邮件吗?它告诉你你可以试试psycopg2-binary。就 Python 而言,该软件包仍将安装 psycopg2
  • AKX 我确实尝试过,甚至我首先尝试安装 psycopg2-binary 之前只是 pscopg2,因为我确实在 windows 和 linux 中有一个环境,并且 linux 需要安装 psycopg2-binary 而不仅仅是 psycopg2。但是,是的,我试过了
  • “windows 和 Linux 中的环境”是什么意思?这与你的 MacBook 有什么关系? (是 Intel 机器还是 Apple Silicon?)
  • 是的,它是苹果芯片,它是 M1,当我说环境时,我的意思是我的一切工作正常,一切都安装好并且工作正常,包括 psycopg2,我是 MacOS 新手,所以我正在为一些安装而苦苦挣扎
  • 那么这个问题可能会有所帮助。我通过谷歌搜索psycopg2 m1 找到了它。 github.com/psycopg/psycopg2/issues/1286

标签: python-3.x django backend psycopg2


【解决方案1】:

尝试使用以下命令:

pip3 install psycopg2-binary

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

迟到了,但我刚刚遇到了这个问题,但我没有找到任何解决办法。我试图在新 Mac 上为正在进行的项目安装 requirements.txt。最后我记得它是一个 postgresql 包,我还没有安装 postgresql。一旦我安装了 postgresql 并尝试再次安装 psycopg2,它就可以正常工作,没有错误。

【讨论】:

    【解决方案3】:

    正如 Alex 所提到的,是您的系统上未安装 PostGreSQL 引发错误 安装 PostGreSQL,一切正常 试试这个

    ❯ brew install postgresql
    # If you open a new terminal tab you will see that pg_config is available
    ❯ export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
    ❯ export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib -L${HOME}/.pyenv/versions/3.8.10/lib"
    ❯ python -V
    Python 3.9.13
    ❯ pip install psycopg2-binary==2.8.6```
    

    【讨论】:

      猜你喜欢
      • 2021-08-06
      • 2021-08-30
      • 2021-02-25
      • 1970-01-01
      • 2014-03-14
      • 1970-01-01
      • 2016-04-30
      • 1970-01-01
      • 2019-06-10
      相关资源
      最近更新 更多