skip to Main Content

I had an Azure function that worked completely fine, then I added the pytz package to my script.

In Azure I am getting the error:

ModuleNotFoundError: No module named ‘pytz’.

My requirements.txt file looks like this:

azure-functions
pyodbc==4.0.32
requests==2.28.0
pytz==2022.1

and the top of my actual script looks like this:

import datetime
import logging
import requests
import json
import pyodbc
import azure.functions as func
from datetime import datetime
from pytz import timezone

When I deploy the function from Python, I can see the packages getting installed in the output EXCEPT for pytz. Is it because in my script it is written as ‘from pytz’? I am very new to Python and appreciate any help.

2

Answers


  1. Microsoft has given a solution and troubleshooting steps for this kind of error with detailed explanation that:

    The Module Not Found error may not occur when you’re using Windows or macOS for local development. However, the package fails to import on Azure Functions, which uses Linux at runtime. This is likely to be caused by using pip freeze to export virtual environment into requirements.txt

    To mitigate this error, there are 2 solutions given by Microsoft which are replace the equivalent package or Handcraft requirements.txt file.

    Check this document given by Microsoft.

    Login or Signup to reply.
  2. After reproducing from my end, In my case the problem was with the python environment. Though the python environment is present make sure you activate the environment.

    enter image description here

    After activating i.e., <Your_Environment_Name>ScriptsActivate.ps1

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search