使用Django Cookiecutter模板时postgres未安装/配置问题求助
Postgres命令提示"command not found"问题排查(《A Wedge of Django》学习场景)
问题描述
跟随《A Wedge of Django》学习,使用Cookiecutter模板框架时,执行pg_isready检查Postgres运行状态、postgres -V查看版本均返回zsh: command not found错误。已严格按照书中19.3.3章节步骤操作,处于正确项目目录,但无法继续推进。
命令行执行输出:
(everycheese) joshp@joshs-mbp-2 everycheese % pg_isready zsh: command not found: pg_isready (everycheese) joshp@joshs-mbp-2 everycheese % postgres -V zsh: command not found: postgres (everycheese) joshp@joshs-mbp-2 everycheese % ls CONTRIBUTORS.md env.sample.windows requirements COPYING everycheese requirements.txt README.md locale setup.cfg config manage.py env.sample.mac_or_linux pytest.ini
排查与解决步骤
1. 确认Postgres是否已安装
先检查系统中是否存在Postgres:
- 若用Homebrew安装,执行:
brew list | grep postgresql - 若用官方安装包,检查默认安装目录:
ls /Library/PostgreSQL/
如果无输出,说明未安装,重新安装:
- Homebrew方式:
brew install postgresql - 官方安装包:下载对应版本安装包完成安装
2. 修复环境变量PATH
Postgres的命令行工具路径未加入系统PATH是常见原因,不同安装方式的路径如下:
- Homebrew(Intel Mac):
/usr/local/bin - Homebrew(M系列Mac):
/opt/homebrew/bin - 官方安装包:
/Library/PostgreSQL/<你的版本号>/bin
操作步骤:
- 查看当前PATH:
echo $PATH - 打开zsh配置文件:
open ~/.zshrc - 添加对应路径到配置文件(示例为M系列Homebrew安装):
export PATH="/opt/homebrew/bin:$PATH" - 生效配置:
source ~/.zshrc
3. 验证修复结果
重新执行以下命令,确认正常输出:
postgres -V # 应显示Postgres版本号 pg_isready # 应显示"accepting connections"或对应状态信息
4. 同步项目数据库配置
确保项目的环境配置文件(复制env.sample.mac_or_linux为.env)中数据库连接URL正确,示例:
DATABASE_URL=postgres://localhost:5432/everycheese
内容的提问来源于stack exchange,提问作者jpanknin
相关产品推荐
相关产品推荐

