5

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

需求.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但一样。

请指教。

4

2 回答 2

3

我感谢@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. 将以下内容放入 .zshrcexport 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. 将以下内容放入 .zshrcexport 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. 一个 abt openssl
  2. 一个abt libpq
于 2021-12-25T18:45:56.463 回答
2

您需要openssl使用 brew安装

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

于 2021-12-25T11:53:01.967 回答