This is a bug tracker
If you have a question, such has "how do you do X with Python/PostgreSQL/psycopg2" please write to the mailing list or open a question instead.
Please complete the following information:
OS: macOS Sonoma 14.2 @ MBAir M2
Psycopg version: 2.9.9
Python version: 3.12.1
PostgreSQL version: 11.22 (in a docker container but PyCharm connected successfully)
pip version 23.3.1
Describe the bug
Please let us know:
1: what you did
I have installed SQLAlchemy and tried to create an async engine. It doesn't really matter whether I create a regular or async engine. Ive tried both psycopg2 and psycopg2-binary.
2: what you expected to happen
I have expected a working postgresql engine :)
3: what happened instead
ImportError was raised.
If possible, provide a script reproducing the issue.
Script:
import os
import sqlalchemy
from dotenv import load_dotenv
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import DeclarativeBase
load_dotenv()
SQLALCHEMY_DATABASE_URL = sqlalchemy.URL.create(
drivername=os.getenv("SQL_DRIVER"), username=os.getenv("POSTGRES_USER"), password=os.getenv("POSTGRES_PASSWORD"),
host=os.getenv("POSTGRES_HOST"), port=os.getenv("POSTGRES_PORT"), database=os.getenv("POSTGRES_DB"), )
engine = create_async_engine(
SQLALCHEMY_DATABASE_URL, echo=True
)
class Base(DeclarativeBase):
pass
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1527, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "./app/sql_app/create_db.py", line 3, in <module>
from app.sql_app.database import Base, engine
File "./app/sql_app/database.py", line 15, in <module>
engine = create_async_engine(
^^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.12/site-packages/sqlalchemy/ext/asyncio/engine.py", line 117, in create_async_engine
sync_engine = _create_engine(url, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 2, in create_engine
File "./venv/lib/python3.12/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 601, in create_engine
dbapi = dbapi_meth(**dbapi_args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 690, in import_dbapi
import psycopg2
File "./venv/lib/python3.12/site-packages/psycopg2/__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(./venv/lib/python3.12/site-packages/psycopg2/_psycopg.cpython-312-darwin.so, 0x0002): Library not loaded: @rpath/libpq.5.dylib
Referenced from: <5F71694B-7580-341A-A0CF-E1068C40A546> ./venv/lib/python3.12/site-packages/psycopg2/_psycopg.cpython-312-darwin.so
Reason: no LC_RPATH's found
This is a bug tracker If you have a question, such has "how do you do X with Python/PostgreSQL/psycopg2" please write to the mailing list or open a question instead.
Please complete the following information:
Describe the bug Please let us know:
1: what you did I have installed SQLAlchemy and tried to create an async engine. It doesn't really matter whether I create a regular or async engine. Ive tried both psycopg2 and psycopg2-binary.
2: what you expected to happen I have expected a working postgresql engine :)
3: what happened instead ImportError was raised.
If possible, provide a script reproducing the issue.
Script:
Traceback:
pip freeze
: