ModuleNotFoundError: No module named 'psycopg2._psycopg'. Please check the requirements.txt file for the missing module.

Raghavendra Boralli (US) 0 Reputation points
2023-07-07T08:05:43.23+00:00

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.

  1. 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,

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,932 questions
Azure Database for PostgreSQL
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,941 Reputation points Moderator
    2023-07-10T05:35:25.6933333+00:00

    @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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.