我正在尝试使用 Postgres 数据库运行 Django 项目。我使用通过 postgressapp 安装的 Postgres 13.4(具有所有当前支持的版本的通用版本)和 python 3.9(在 venv 中)。我在配备 Apple M1 芯片的 Mac、macOS Big Sur 上工作。
\n我遇到了以下众所周知的问题:
\ndjango.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/mymac/PyCharmProjects/projectname/venv/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Library not loaded: /opt/homebrew/opt/postgresql/lib/libpq.5.dylib\n\xc2\xa0 Referenced from: /Users/mymac/PyCharmProjects/projectname/venv/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so\n\xc2\xa0 Reason: image not found\nRun Code Online (Sandbox Code Playgroud)\n通过搜索,我发现了一些这样的讨论:https://github.com/psycopg/psycopg2/issues/1216。看来最相关的解决方案是“RyanDurk\xc2\xa0commented\xc2\xa0on Jan 27”:
$ brew install libpq --build-from-source\n\n$ export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"\n\n$ pip install psycopg2\nRun Code Online (Sandbox Code Playgroud)\n不幸的是,就我而言,它没有帮助。
\n然后,我在这里找到了一些建议:Library not returned: /usr/local/lib/libpq.5.4.dylib并尝试了它们。特别是,我尝试通过符号链接访问 libpq.5.dylib,例如:\nln -s\xc2\xa0 /Library/PostgreSQL/13/lib/libpq.5.dylib /opt/homebrew/opt/postgresql/lib/libpq.5.dylib(该解决方案标记为主题启动器接受),但也没有成功。
我尝试从 postgresql.org 安装 postgres,然后使用 homebrew 卸载/重新安装 …