azure-functions-python-worker: ModuleNotFoundError: No module named 'azure'
I’m trying to run a web scraper via an Azure Function. When I run the function locally, it works no problem. But when I deploy the function to Azure I encounter a couple of ModuleNotFoundError Exceptions even though I’ve included both files in requirements.txt. I saw some other people ran into this issue, I tried the solutions in these posts but haven’t got anything to work.
Investigative information
- Function App name: scrapertest1
- Function name(s) (as appropriate): ScraperTest
- Core Tools version: 2.7.2254
Repro steps
Provide the steps required to reproduce the problem:
I use func azure functionapp publish scrapertest1 --build remote to deploy the app and monitor it from the live metrics stream.
Expected behavior
I expect the function to see the ‘azure’ and ‘bs4’ modules that work fine when I run the function locally.
Actual behavior
The function is deployed successfully but whenever my function tries to run it fails due to ModuleNotFoundError exceptions.
Known workarounds
I tried several different ways of deploying the function, all unsuccessful in getting around the issue:
func azure functionapp publish scrapertest1 --build remote
func azure functionapp publish scrapertest1
func azure functionapp publish scrapertest1 --build-native-deps --force
Contents of the requirements.txt file:
appdirs==1.4.3
azure
beautifulsoup4==4.8.2
bs4==0.0.1
certifi==2019.11.28
cfgv==3.0.0
chardet==3.0.4
distlib==0.3.0
filelock==3.0.12
identify==1.4.11
idna==2.8
importlib-metadata==1.5.0
lxml==4.5.0
nodeenv==1.3.5
pre-commit==2.1.0
PyYAML==5.3
requests==2.22.0
selenium==3.141.0
six==1.14.0
soupsieve==1.9.5
toml==0.10.0
urllib3==1.25.8
zipp==3.0.0
azure-storage-file-datalake
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 25 (8 by maintainers)
For me, there is a lot of confusion in docs about “How to deploy a Python Function in Linux Consumption Plan”. The docs are various in nature and tells a different story. From what I see, I am running from a deployment package . What it does is build everything and mounts it to /home/site/wwwroot/ folder. So what you gotta do is pack everything before you publish like this
pip3.7 install --target $(System.DefaultWorkingDirectory)/.python_packages/lib/site-packages -r requirements.txtThat resolved the "import requests " issue but I am still getting other import issues. I am using the template so that it could be different from you. Can you share your cli commands to publish?
@anirudhgarg I tried doing as you suggested, the ModuleNotFoundError Exceptions persist
I am getting the same error but with the “requests” module. I am using the pipeline suggested by Microsft. Everything works in the local but the Applications Metrics logs are showing otherwise.
@anirudhgarg I think I might have figured out the issue. Seems like the problem might have been related to the way I was calling my Python script from the
__init__.pyfile. I’m importing the file like this now (as it says so in the docs):from . import my_filewhereas before I was using the subprocess module. This seems to fix the issue for the bs4 package import error, I’ll see now if it resolves the other Azure import errorHi @stefanlenoach,
The azure module is not compatible with the azure-storage package. You can see this in the PyPI page https://pypi.org/project/azure/
This package is not compatible with azure-storageThe azure-storage-file-datalake module you use has a dependency on azure-storage-blob, it will be installed while deployment, which breaks the parent azure module.
Please consider removing the azure module and manually pick the packages you need in your requirements.txt.