I’m trying to use psycopg2-binary for my flask app in python however it is not working even though I have psycopg2-binary already installed using pip. I am using windows 11
This is my code:
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://postgres.qgleopwuhtawykfvcucq:[mypassword]@aws-0-us-west-1.pooler.supabase.com:6543/postgres"
db.init_app(app)
@app.route("/")
def home():
return render_template("index.html")
if __name__ == "__main__":
app.run()
This is my error:
Traceback (most recent call last):
File "c:UsersnbezaWebsitemain.py", line 7, in <module>
db.init_app(app)
~~~~~~~~~~~^^^^^
File "C:UsersnbezaAppDataLocalProgramsPythonPython313Libsite-packagesflask_sqlalchemyextension.py", line 374, in init_app
engines[key] = self._make_engine(key, options, app)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "C:UsersnbezaAppDataLocalProgramsPythonPython313Libsite-packagesflask_sqlalchemyextension.py", line 665, in _make_engine
return sa.engine_from_config(options, prefix="")
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "C:UsersnbezaAppDataLocalProgramsPythonPython313Libsite-packagessqlalchemyenginecreate.py", line 820, in engine_from_config
return create_engine(url, **options)
File "<string>", line 2, in create_engine
File "C:UsersnbezaAppDataLocalProgramsPythonPython313Libsite-packagessqlalchemyutildeprecations.py", line 281, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
File "C:UsersnbezaAppDataLocalProgramsPythonPython313Libsite-packagessqlalchemyenginecreate.py", line 599, in create_engine
dbapi = dbapi_meth(**dbapi_args)
File "C:UsersnbezaAppDataLocalProgramsPythonPython313Libsite-packagessqlalchemydialectspostgresqlpsycopg2.py", line 690, in import_dbapi
import psycopg2
File "C:UsersnbezaAppDataLocalProgramsPythonPython313Libsite-packagespsycopg2__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
...<10 lines>...
)
ImportError: DLL load failed while importing _psycopg: The specified module could not be found.
I’m not why this is happening. I am trying to connect my flask app to Supabase.
New contributor
Nikos Bezas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.