我删除了Postgres.app桌面应用程序,将Postgres.app从9.6降级到9.5。我通过
更新了数据库(我通过下载Postgres.app桌面应用程序下载了Postgres,我通过pip install 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应用程序中进行迁移时,看起来路径仍然指向Postgress的9.6版本
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
答案 0 :(得分:2)
这解决了我的问题:
卸载你的psycopg2
pip uninstall psycopg2
然后执行此操作
pip --no-cache-dir install -U psycopg2
答案 1 :(得分:1)
我认为您的问题是当前安装的psycopg2
版本引用了与之前安装的postgres(/Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib
)捆绑在一起的C postgres库。
尝试卸载并重新安装psycopg2
。
pip uninstall psycopg2
pip install psycopg2