Mac 安装psycopg2出错:Error:pg_config executable not found的解决

在mac 上执行pip3 install psycopg2-binary出现如下错误:

python 复制代码
Error:pg_config executable not found

然后我又到终端里执行

python 复制代码
brew install  postgresql@16 

显示

python 复制代码
Warning: You are using macOS 15.
We do not provide support for this pre-release version.
It is expected behaviour that some formulae will fail to build in this pre-release version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from Homebrew or its maintainers on social media.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.

以为是安装的psycopg2 版本问题,试了安装15、16都出现以上警告。

解决办法:

1、更新brew版本

python 复制代码
brew update

2、然后再安装postgresql@16

python 复制代码
brew install postgresql@16

postgresql安装成功

3、添加路径

python 复制代码
vim ~/.bash_profile
python 复制代码
export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/postgresql@16/lib"
export CPPFLAGS="-I/opt/homebrew/opt/postgresql@16/include"

保存后退出,

再执行

python 复制代码
source ~/.bash_profile

4、安装psycopg2-binary

到IDE中,执行

python 复制代码
pip3 install psycopg2-binary

完美安装成功!

相关推荐
總鑽風8 小时前
搭建Spring Boot + ELK日志平台,实现可视化日志监控
spring boot·elk·macos
CS创新实验室14 小时前
《计算机网络》深入学:IP地址 VS. MAC地址
tcp/ip·计算机网络·macos
是孑然呀14 小时前
mac m4mini安装软件
macos
简单点了14 小时前
mac安装Java环境
java·macos
涔溪14 小时前
腾讯 WorkBuddy 超详细卸载清理文档(适用于 Windows 1011 + macOS 全版本,彻底卸载、不留残留)
windows·macos·ai·workbuddy
简单点了15 小时前
mac安装idea
java·macos·intellij-idea
涔溪16 小时前
腾讯 WorkBuddy 超详细安装教程(Windows+macOS 全步骤)
windows·macos·workbuddy
一个人旅程~16 小时前
如何解决跨平台(macos/win)与跨app软件工具(Pages、Keynote/office等)的字体错乱与排版混乱问题?(完整版)
linux·windows·经验分享·macos·电脑
aosky2 天前
手机远程畅玩OpenAI Codex
macos·智能手机·cocoa
A懿轩A2 天前
【2026 最新】Python 下载与安装:在 macOS 下使用 Homebrew 和 pyenv 完美管理多版本 Python
python·macos·mac