Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named 'psycopg2' when using DB_BACKUP with postgresql:// engine #796

Open
rromanchuk opened this issue Feb 12, 2023 · 2 comments

Comments

@rromanchuk
Copy link

acarshub      | [webapp      ] 2023/02/12 17:46:18 ModuleNotFoundError: No module named 'psycopg2'
acarshub      | [webapp      ] 2023/02/12 17:46:18 LOG_LEVEL set to 4
acarshub      | [webapp      ] 2023/02/12 17:46:18 INFO:[database]:         Downloading Station IDs
acarshub      | [webapp      ] 2023/02/12 17:46:18 INFO:[database]:         Completed loading Station IDs
acarshub      | [webapp      ] 2023/02/12 17:46:18 INFO:[database]:         Downloading message labels
acarshub      | [webapp      ] 2023/02/12 17:46:18 INFO:[database]:         Completed loading message labels
acarshub      | [webapp      ] 2023/02/12 17:46:18 Starting web service
acarshub      | [webapp      ] 2023/02/12 17:46:20 [2023-02-12 17:46:20 -0600] [964] [ERROR] Exception in worker process
acarshub      | [webapp      ] 2023/02/12 17:46:20 Traceback (most recent call last):
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker
acarshub      | [webapp      ] 2023/02/12 17:46:20     worker.init_process()
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/gunicorn/workers/geventlet.py", line 143, in init_process
acarshub      | [webapp      ] 2023/02/12 17:46:20     super().init_process()
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/gunicorn/workers/base.py", line 134, in init_process
acarshub      | [webapp      ] 2023/02/12 17:46:20     self.load_wsgi()
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/gunicorn/workers/base.py", line 146, in load_wsgi
acarshub      | [webapp      ] 2023/02/12 17:46:20     self.wsgi = self.app.wsgi()
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/gunicorn/app/base.py", line 67, in wsgi
acarshub      | [webapp      ] 2023/02/12 17:46:20     self.callable = self.load()
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/gunicorn/app/wsgiapp.py", line 58, in load
acarshub      | [webapp      ] 2023/02/12 17:46:20     return self.load_wsgiapp()
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
acarshub      | [webapp      ] 2023/02/12 17:46:20     return util.import_app(self.app_uri)
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/gunicorn/util.py", line 359, in import_app
acarshub      | [webapp      ] 2023/02/12 17:46:20     mod = importlib.import_module(module)
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
acarshub      | [webapp      ] 2023/02/12 17:46:20     return _bootstrap._gcd_import(name[level:], package, level)
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "<frozen importlib._bootstrap_external>", line 790, in exec_module
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/webapp/acarshub.py", line 22, in <module>
acarshub      | [webapp      ] 2023/02/12 17:46:20     import acarshub_helpers  # noqa: E402
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/webapp/acarshub_helpers.py", line 21, in <module>
acarshub      | [webapp      ] 2023/02/12 17:46:20     import acarshub_database
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/webapp/acarshub_database.py", line 88, in <module>
acarshub      | [webapp      ] 2023/02/12 17:46:20     database_backup = create_engine(acarshub_configuration.DB_BACKUP)
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "<string>", line 2, in create_engine
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/util/deprecations.py", line 277, in warned
acarshub      | [webapp      ] 2023/02/12 17:46:20     return fn(*args, **kwargs)  # type: ignore[no-any-return]
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/engine/create.py", line 605, in create_engine
acarshub      | [webapp      ] 2023/02/12 17:46:20     dbapi = dbapi_meth(**dbapi_args)
acarshub      | [webapp      ] 2023/02/12 17:46:20   File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 667, in import_dbapi
acarshub      | [webapp      ] 2023/02/12 17:46:20     import psycopg2
acarshub      | [webapp      ] 2023/02/12 17:46:20 ModuleNotFoundError: No module named 'psycopg2'
@rromanchuk rromanchuk changed the title No module named 'psycopg2' when using - DB_BACKUP=postgresql://user:pass@hostname/db No module named 'psycopg2' when using DB_BACKUP with postgresql:// engine Feb 12, 2023
@rromanchuk
Copy link
Author

I'll poke around, https://github.com/sdr-enthusiasts/docker-acarshub/blob/main/rootfs/webapp/requirements.txt
sqlalchemy should cover it, but looks like only up to 14. My endpoint is on 15, so maybe it trips it up.

https://docs.sqlalchemy.org/en/20/dialects/index.html

@yellingsoftly
Copy link

yellingsoftly commented Apr 13, 2024

Just thought I would add here for anyone else coming across this. I got this working. I tried 14 and 15 and 16 and no use. At the time of writing sqlalchemy supports up to 15. What it ended up being is I had to run the docker image as a build instead of image to install psycopg2 into the container.

For example in your yml.
remove image: line for acarshub
add the below
build:
dockerfile: Dockerfile

Create a text file named Dockerfile in the same directory as your yml file.
Inside put in the below
FROM ghcr.io/sdr-enthusiasts/docker-acarshub:latest
RUN apt-get update && apt-get -y install libpq-dev gcc && apt-get install python3-psycopg2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants