ModuleNotFoundError: No module named 'azure'
See original GitHub issueI’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
Issue Analytics
- State:
- Created 4 years ago
- Comments:25 (8 by maintainers)
Top GitHub Comments
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.txt
That 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 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__.py
file. I’m importing the file like this now (as it says so in the docs):from . import my_file
whereas 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 error