https://pantsbuild.org/ logo
#general
Title
# general
c

curved-microphone-39455

01/12/2023, 11:21 PM
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

happy-kitchen-89482

01/13/2023, 12:34 AM
Do you see psycopg2 in
./pants dependencies src/services/a/run.py
c

curved-microphone-39455

01/13/2023, 12:35 AM
nope, but I see the dep to my library A
h

happy-kitchen-89482

01/13/2023, 12:36 AM
./pants dependencies --transitive src/services/a/run.py
c

curved-microphone-39455

01/13/2023, 12:37 AM
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

happy-kitchen-89482

01/13/2023, 12:38 AM
Add an explicit dep on it
although, I would expect it to be brought in via sqlalchemy
c

curved-microphone-39455

01/13/2023, 12:39 AM
an explicit dep in the BUILD via the poetry requirements or directly in the code?
h

happy-kitchen-89482

01/13/2023, 12:42 AM
In the BUILD file
How are you depending on sqlalchemy?
c

curved-microphone-39455

01/13/2023, 12:43 AM
flask-sqlalchemy
h

happy-kitchen-89482

01/13/2023, 12:43 AM
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

curved-microphone-39455

01/13/2023, 12:48 AM
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

happy-kitchen-89482

01/13/2023, 2:16 AM
Great!
8 Views