Ok, that make couple of hours I am trying to solve...
# general
c
Ok, that make couple of hours I am trying to solve this one, when I try to run a python project, I have a problem with
psycopg2
that is not installed correctly. I have
Service A
that have
Library A
installed with
poetry add -e ../../libraries/a
and this lib have the
psycopg2-binary
in the
pyproject.toml
, if I try to run
poetry run python run.py
which is the entrypoint of my
Service A
everything run perfectly, but when I do
./pants run src/services/a/run.py
I get everytime... (same when I build a Docker container with
./pants package
the container image is done ok but when I run it same error)
Copy code
File "/home/cerberus/.cache/pants/named_caches/pex_root/venvs/s/71f9e365/venv/lib/python3.10/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 811, in dbapi
    import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
in my
BUILD
file in
Library A
I have tested every possible combination of
module_mapping
and
overrides
to try to make it works.
1
h
Do you see psycopg2 in
./pants dependencies src/services/a/run.py
c
nope, but I see the dep to my library A
h
./pants dependencies --transitive src/services/a/run.py
c
I am not in front of my computer atm, but I will test this asap, if it is not listed, what would be the next step?
h
Add an explicit dep on it
although, I would expect it to be brought in via sqlalchemy
c
an explicit dep in the BUILD via the poetry requirements or directly in the code?
h
In the BUILD file
How are you depending on sqlalchemy?
c
flask-sqlalchemy
h
Looks like sqlalchemy will only bring in psycopg2 if you depend on the
postgresql
extra
If you don't do that, you have to bring it in yourself, via an explicit dependency in the BUILD file
c
if I add sqlalchemy with the extra postgresql directly with poetry, will pants will pick it up?
Thanks btw, I will test this tonight, adding
poetry add 'sqlalchemy[postgresql]'
in my library
it works! Thanks you so much @happy-kitchen-89482 you are a lifesaver
h
Great!