Been trying to implement a django app with postgresql database on heroku, with psycopg2 as the backend.
(Based on the research I've done, psycopg3 looks like it's not really built for that purpose)
My app works, without issue running inside heroku/heroku console, and connects to db fine.
But running locally (python manage.py runserver), it just can't detect the psycopg2 module. I've reinstalled the module in and out of a venv. I've tried the binary install, used -pep517 method as well.
I saw a thread here indicating newer python may not be compatible, but it didn't really provide any concrete proof as far as I could tell.
Any advise in this regard, or perhaps a better backend adapter suggestion for Django + postgres?
below are the relevant portions of settings.py in the django project directory:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '*db info here'
...more db creds
}
}
and the error:
File "C:\*userdirectory*\djangenv\Lib\site-packages\django\db\backends\postgresql\base.py", line 24, in <module>
import psycopg2 as Database
File "C:\*userdirectory*\djangenv\Lib\site-packages\psycopg2\__init__.py", line 51, in
<module> from psycopg2._psycopg import ( # noqa
ImportError: DLL load failed while importing _psycopg: The specified module could not be
found.
sqlite3
db for my local dev work and then use postgres for my prod by doing a sym link with different settings, So I'd recommend just doing that. But if you googleImportError: DLL load failed while importing _psycopg
, you'll find others that ran into this issue, specifically on windows, maybe there's a fix that already exists in those questionsdjango.db.backends.postgresql_psycopg2
pip install psycopg2-binary