AbhimanyuHK / aws-psycopg2

A aws psycopg2 package from psycopg2 https://pypi.org/project/aws-psycopg2/
75 stars 11 forks source link

1.3.8 import error `No module named 'psycopg2'` on Jenkins #11

Closed j-adamczyk closed 2 years ago

j-adamczyk commented 2 years ago

I am installing aws-psycopg2 using Poetry:

[tool.poetry.dependencies]
python = "^3.9"

# beware - this is time-handling library, NOT PyArrow for handling Parquet files!
arrow = "*"
aws-psycopg2 = "*"
boto3 = "*"
requests = "*"

[tool.poetry.dev-dependencies]
black = "*"
coverage = "*"
freezegun = "*"
mock = "*"
nose = "*"
pylint = "*"
pytest = "*"

The generated requirements.txt has aws-psycopg2==1.3.8.

Everythings works locally on a fresh environment, PyCharm detects everything and I checked on disk and everything is there. However, on Jenkins it does not work. Relevant Jenkinsfile.groovy part:

    sh 'apk add libffi-dev'
    sh 'pip install --upgrade pip && pip install poetry'
    sh 'poetry export --without-hashes --dev -f requirements.txt -o requirements.txt --with-credentials'
    sh 'pip install -r requirements.txt'

I just do pip install -r requirements.txt there and then I get:

14:19:08    File "/home/jenkins/agent/workspace/_repo_name_PR-24/lib/db_connector.py", line 6, in <module>
14:19:08      import psycopg2
14:19:08  ModuleNotFoundError: No module named 'psycopg2'

Curiously, everything works when deployed on AWS. Do you have any idea why this may be happening? Or if this may be the case for this library, or just my Jenkins setup?

j-adamczyk commented 2 years ago

Interestingly, on the next run (identical, without any changes), error changed to:

14:40:53    File "/home/jenkins/agent/workspace/_repo_name_PR-24/lib/db_connector.py", line 6, in <module>
14:40:53      import psycopg2
14:40:53    File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 51, in <module>
14:40:53      from psycopg2._psycopg import (                     # noqa
14:40:53  ImportError: Error loading shared library libresolv.so.2: No such file or directory (needed by /usr/local/lib/python3.9/site-packages/psycopg2/../psycopg2_binary.libs/libgssapi_krb5-497db0c6.so.2.2)
j-adamczyk commented 2 years ago

I realized that the error was connected to this one, not to the aws-psycopg2.