PostgreSQL connection library for Python not installed
andrewminer
PROOP

a month ago

My cron failed to run this morning with the following error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/app/authmo/venv/lib/python3.13/site-packages/authmo_www/script/morning.py", line 43, in <module>
    with database.openTransaction():
         ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/app/authmo/venv/lib/python3.13/site-packages/authmo_sql/database.py", line 140, in __enter__
    self.connect()
    ~~~~~~~~~~~~^^
  File "/app/authmo/venv/lib/python3.13/site-packages/authmo_sql/database.py", line 71, in connect
    self._connection = self.engine.connect()
                       ^^^^^^^^^^^
  File "/app/authmo/venv/lib/python3.13/site-packages/authmo_sql/database.py", line 52, in engine
    self.startup()
    ~~~~~~~~~~~~^^
  File "/app/authmo/venv/lib/python3.13/site-packages/authmo_sql/database.py", line 180, in startup
    self._engine = sqlalchemy.create_engine(self._url)
                   ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "<string>", line 2, in create_engine
  File "/app/authmo/venv/lib/python3.13/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
  File "/app/authmo/venv/lib/python3.13/site-packages/sqlalchemy/engine/create.py", line 617, in create_engine
    dbapi = dbapi_meth(**dbapi_args)
  File "/app/authmo/venv/lib/python3.13/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 696, in import_dbapi
    import psycopg2
  File "/app/authmo/venv/lib/python3.13/site-packages/psycopg2/__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
    ...<10 lines>...
    )
ImportError: libpq.so.5: cannot open shared object file: No such file or directory

My project's build step completed successfully, and specifically mentions installing the connector library, psycopg2 :

Building wheels for collected packages: authmo_sql, psycopg2
  Building wheel for authmo_sql (pyproject.toml): started
  Building wheel for authmo_sql (pyproject.toml): finished with status 'done'
  Created wheel for authmo_sql: filename=authmo_sql-1.0.0-py3-none-any.whl size=22195 sha256=c75526e9d4edfebeabc441dd9fd73b6d8dc30a0b165e830654ffaa953dc2aca2
  Stored in directory: /tmp/pip-ephem-wheel-cache-ssre_b2t/wheels/9c/44/04/fab7eccfaf0a1aef5bf4c2adf85974588f203a818037b1c267
  Building wheel for psycopg2 (pyproject.toml): started
  Building wheel for psycopg2 (pyproject.toml): finished with status 'done'
  Created wheel for psycopg2: filename=psycopg2-2.9.11-cp313-cp313-linux_x86_64.whl size=521119 sha256=9ebec35e46b2d587985fffb6e7ff4041b92bbc17f1eecf7669760b80b74f5069
  Stored in directory: /root/.cache/pip/wheels/63/ed/1a/7f7f58e98cbe6623951e4308d81a93c8087d1ac9804513a056
Successfully built authmo_sql psycopg2
Installing collected packages: typing-extensions, psycopg2, greenlet, sqlalchemy, authmo_sql

Successfully installed authmo_sql-1.0.0 greenlet-3.3.1 psycopg2-2.9.11 sqlalchemy-2.0.46 typing-extensions-4.15.0

This library is usually installed with psycopg2, and it working normally in all my other instances (e.g., the www-web instance in the same project). It appears there is something incorrect happening with the installation process itself.

$20 Bounty

3 Replies

Railway
BOT

a month ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open Railway 29 days ago


darseen
HOBBYTop 5% Contributor

a month ago

Try to install psycopg2-binary instead of psycopg2


darseen

Try to install psycopg2-binary instead of psycopg2

andrewminer
PROOP

a month ago

I'd prefer not to do that until I understand why this one instance is different from all the other instances I have which work just fine using only psycopg2 on its own. The fact that this one case is different feels like something broken on the infrastructure level, rather than simply using the wrong package.


andrewminer

I'd prefer not to do that until I understand why this one instance is different from all the other instances I have which work just fine using only psycopg2 on its own. The fact that this one case is different feels like something broken on the infrastructure level, rather than simply using the wrong package.

darseen
HOBBYTop 5% Contributor

a month ago

If your runtime image is a slimmed down linux version that doesn't have the postgresql client libraries installed, it could cause this issue.

This is why it works in other instances (like your web instance), those likely use a different base image. That's why I suggested to use psycopg2-binary , as it's likely to have the necessary libs. If this doesn't work, you can try to install the postgresql libraries in the runtime environment during the build.


Loading...