【问题标题】:When run `pip-compile requirements.in` in macOS12 monterey using venv python-3.9.9, pg_config not found使用 venv python-3.9.9 在 macOS12 monterey 中运行“pip-compile requirements.in”时,找不到 pg_config
【发布时间】:2022-01-22 02:10:54
【问题描述】:

操作系统:monterey macOSv12.0.1 python venv: 3.9.9

requirements.in

# To update requirements.txt, run:
#
#    pip-compile requirements.in
#
# To install in localhost, run:
#
#    pip-sync requirements.txt
#

django==3.2.10  # https://www.djangoproject.com/

psycopg2-binary==2.9.2 # https://github.com/psycopg/psycopg2

打开venv后,我输入pip-compile requirements.in,然后我得到一堆关于pg_config not found的错误

这是我的 asciinema https://asciinema.org/a/sl9MqmrayLAR3rRxEul4mYaxw

我试过env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib' pip-compile requirements.in,但还是一样。

请指教。

【问题讨论】:

    标签: python macos pip-tools


    【解决方案1】:

    感谢@Vishnudev 和@cetver 的其他 2 个回答?

    但我尝试使用 brew install 安装 postgresql,花了很长时间,20 分钟后我仍然无法完成。

    我在谷歌上搜索了很多次后终于弄明白了

    以下是我的情况的技术规格:

    1. 蒙特雷 12.1.0
    2. 苹果硅
    3. zsh

    概念

    从概念上讲,我所做的是:

    1. 安装 openssl,打开所有与之相关的导出,
    2. 然后安装 libpq,打开与之相关的所有导出,
    3. 然后开启python venv

    这是我采取的步骤。完全有可能不需要所有步骤。但是我的时间有限,所以他们来了。

    步骤

    1. brew install openssl
    2. 将以下内容放入 .zshrc export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
    3. 将以下内容放入 .zshenv
    export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
    export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
    export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"
    
    1. source ~/.zshrc
    2. brew install libpq
    3. 将以下内容放入 .zshrc export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
    4. 将以下内容放入 .zshenv
    export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
    export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
    export PKG_CONFIG_PATH="/opt/homebrew/opt/libpq/lib/pkgconfig"
    
    1. source ~/.zshenv
    2. 开启venv
    3. 现在 psycopg2-binary 的安装应该可以工作了

    对我有帮助的链接:

    1. the one abt openssl
    2. the one abt libpq

    【讨论】:

      【解决方案2】:

      您需要使用 brew 安装 openssl

      brew install openssl
      brew install postgres       # If not installed and if required
      

      通过将以下内容复制到终端或添加到.bashrc来临时全局设置环境变量

      export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
      export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
      

      如果未设置,您还需要设置 PostgreSQL 的路径

      export PATH=/opt/homebrew/opt/postgresql@11/bin:$PATH
      

      记住:将 @___ 替换为您的版本

      然后继续 requirements.txt

      【讨论】:

      • 为什么我必须安装 postgres?我可以不安装 postgres 吗?我通常运行 docker 来运行我的应用程序。我想做的就是使用 pip-tools 生成 requirements.txt
      • 只有在本地运行时才安装。 @KimStacks
      【解决方案3】:

      好像没有安装 Postgres 或者 PATH 变量中缺少 Postgres /bin

      https://postgresapp.com/downloads.html

      $ export PATH=/Applications/Postgres.app/Contents/Versions/<version>/bin/:$PATH

      https://www.psycopg.org/docs/install.html#build-prerequisites

      【讨论】:

      • 为什么我必须安装 postgres?我可以不安装 postgres 吗?我通常运行 docker 来运行我的应用程序。我想做的就是使用 pip-tools 生成 requirements.txt
      • 如果您使用远程数据库,则只需要 libpq-dev 库,就像第二个链接中所说的那样
      猜你喜欢
      • 2019-12-21
      • 2019-05-14
      • 2023-01-11
      • 1970-01-01
      • 2021-01-14
      • 2013-12-08
      • 2020-04-18
      • 2022-08-02
      • 2014-10-27
      相关资源
      最近更新 更多