Hi Team,
When tested locally, the python function app referring to the library psycopg(2) is working fine, but while deploying the same function app via CI/CD pipeline, we are getting the below error , while testing it
ModuleNotFoundError: No module named 'psycopg2._psycopg'. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide:
https://aka.ms/functions-modulenotfound.
The
psycopg2 &
binary library
psycopg2-binary
is indeed added in the requirements.txt
Python 3.9 is used. Below is the script used for installing python dependencies.
python3.9 -m venv worker_venv
source worker_venv/bin/activate
sudo apt-get update
sudo pip3 install --upgrade pip
sudo apt install build-essential libpq-dev python3-dev
sudo pip3 install psycopg2 --upgrade
sudo pip3 install psycopg2-binary --upgrade
sudo pip3 install --target="./.python_packages/lib/site-packages" psycopg2 --upgrade
sudo pip3 install --target="./.python_packages/lib/site-packages" psycopg2-binary --upgrade
sudo pip3 install --target="./.python_packages/lib/site-packages" -r ./requirements.txt --upgrade
Below is error while testing the function app from postman via HTTP trigger
from ..kyvScreeningActivity import kyvScreeningDatabase as kyvdb\\n File \\\"/home/site/wwwroot/kyvScreeningActivity/kyvScreeningDatabase.py\\\", line 12, in <module>\\n import psycopg2\\n File \\\"
/home/site/wwwroot/.python_packages/lib/site-packages/psycopg2/__init__.py
\\\", line 51, in <module>\\n from psycopg2._psycopg import ( # noqa\\n\",\"RemoteMessage\":\"
ModuleNotFoundError: No module named 'psycopg2._psycopg'
.
What I notice is that the library path that is being referred while testing is
/home/site/wwwroot/.python_packages/lib/site-packages/
but the CI/CD is installing the python library in a
different path
, is that an issue? Kindly help .
Thank you,
Regards,
@Raghavendra Boralli (US)
Thanks for reaching out. In case if any module or dependencies cannot be installed using pip (requirement.txt) then you need to use
build native dependencies
or
enable remote build
.
You can refer to
python troubleshooting document
for more details.