[Python] DLL load failed while importing _psycopg: The specified module could not be found

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    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:\Users\nbeza\Website\main.py", line 7, in <module>
    db.init_app(app)
    ~~~~~~~~~~~^^^^^
    File "C:\Users\nbeza\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask_sqlalchemy\extension.py", line 374, in init_app
    engines[key] = self._make_engine(key, options, app)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
    File "C:\Users\nbeza\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask_sqlalchemy\extension.py", line 665, in _make_engine
    return sa.engine_from_config(options, prefix="")
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\nbeza\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\create.py", line 820, in engine_from_config
    return create_engine(url, **options)
    File "<string>", line 2, in create_engine
    File "C:\Users\nbeza\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\util\deprecations.py", line 281, in warned
    return fn(*args, **kwargs) # type: ignore[no-any-return]
    File "C:\Users\nbeza\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\create.py", line 599, in create_engine
    dbapi = dbapi_meth(**dbapi_args)
    File "C:\Users\nbeza\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\dialects\postgresql\psycopg2.py", line 690, in import_dbapi
    import psycopg2
    File "C:\Users\nbeza\AppData\Local\Programs\Python\Python313\Lib\site-packages\psycopg2\__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.

    Continue reading...

Compartilhe esta Página