i通过删除postgres.app桌面应用程序,将postgres.app从9.6降至9.5。我通过执行
更新数据库(我通过下载postgres.app桌面应用程序下载了Postgres,然后通过pip安装django安装了django)
)sudo /usr/libexec/locate.updatedb
看起来它正在从正确的目录启动数据库。
/Applications/Postgres.app/Contents/Versions/9.5/bin/initdb
/Applications/Postgres.app/Contents/Versions/9.5/share/doc/postgresql/html/app-initdb.html
/Applications/Postgres.app/Contents/Versions/9.5/share/man/man1/initdb.1
但是,当我试图在Django应用中进行迁移时,看来该路径仍然指向9.6版Post -Gress
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/tenant_schemas/models.py", line 4, in <module>
from tenant_schemas.postgresql_backend.base import _check_schema_name
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/tenant_schemas/postgresql_backend/base.py", line 14, in <module>
import psycopg2
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: /Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib
Referenced from: /Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found
这为我解决了问题:
-
卸载您的psycopg2
pip卸载psycopg2
-
然后执行此操作
pip -no-cache-dir install -u psycopg2
我认为您的问题是当前安装的psycopg2
的版本是参考文献c Postgres库,该库与您先前安装的Postgres(/Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib
)捆绑在一起。
尝试卸载并重新安装psycopg2
。
pip uninstall psycopg2
pip install psycopg2
它尝试从Symlink /opt/homebrew/opt/postgresql/lib/libpq.5.dylib
加载libpq.5.dylib
,但未找到文件,因此您需要更新它:
# TODO: get this from the error, after "Library not loaded:"
SYMLINK_PATH="/Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib"
# TODO: find this in your machine. The version maybe different than mine
DESTINATION_PATH="/opt/homebrew/opt/postgresql/lib/postgresql@14/libpq.5.dylib"
sudo mv $SYMLINK_PATH $SYMLINK_PATH.old
sudo ln -s $DESTINATION_PATH $SYMLINK_PATH