当 运行 在 macOS12 monterey 中使用 venv python-3.9.9 `pip-compile requirements.in` 时,找不到 pg_config
When run `pip-compile requirements.in` in macOS12 monterey using venv python-3.9.9, pg_config not found
OS: 蒙特雷麦克OSv12.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
的错误
这是我的原图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
但还是一样。
请指教
您需要使用 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
非常感谢@Vishnudev 和@cetver 的其他 2 个回答
但是我尝试使用 brew install 安装 postgresql,这花了很长时间,20 分钟后我仍然无法完成。
经过多次谷歌搜索,我终于弄明白了
以下是我的技术规格:
- 蒙特雷 12.1.0
- 苹果硅
- zsh
概念
从概念上讲,我所做的是:
- 安装 openssl,打开与之关联的所有导出,
- 然后安装 libpq,打开与之关联的所有导出,
- 然后开启python venv
这是我采取的步骤。完全有可能并非所有步骤都需要。但是我的时间有限,所以他们在这里。
步骤
brew install openssl
- 将以下内容放入 .zshrc
export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
- 将以下内容放入.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"
source ~/.zshrc
brew install libpq
- 将以下内容放入 .zshrc
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
- 将以下内容放入.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"
source ~/.zshenv
- 开启 venv
- 现在应该可以安装 psycopg2-binary
对我有帮助的链接:
OS: 蒙特雷麦克OSv12.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
这是我的原图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
但还是一样。
请指教
您需要使用 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
非常感谢@Vishnudev 和@cetver 的其他 2 个回答
但是我尝试使用 brew install 安装 postgresql,这花了很长时间,20 分钟后我仍然无法完成。
经过多次谷歌搜索,我终于弄明白了
以下是我的技术规格:
- 蒙特雷 12.1.0
- 苹果硅
- zsh
概念
从概念上讲,我所做的是:
- 安装 openssl,打开与之关联的所有导出,
- 然后安装 libpq,打开与之关联的所有导出,
- 然后开启python venv
这是我采取的步骤。完全有可能并非所有步骤都需要。但是我的时间有限,所以他们在这里。
步骤
brew install openssl
- 将以下内容放入 .zshrc
export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
- 将以下内容放入.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"
source ~/.zshrc
brew install libpq
- 将以下内容放入 .zshrc
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
- 将以下内容放入.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"
source ~/.zshenv
- 开启 venv
- 现在应该可以安装 psycopg2-binary
对我有帮助的链接: