question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleNotFoundError: No module named 'azure'

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:25 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
gaurcscommented, Mar 9, 2020

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?

1reaction
stefanlenoachcommented, Mar 9, 2020

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modulenotfounderror: no module named azure (Solution )
Modulenotfounderror : no module named azure error occurs when azure python package is not installed or its path is not set properly.
Read more >
[Fixed] ModuleNotFoundError: No module named 'azure- ...
How to Fix “ModuleNotFoundError: No module named 'azure-core'” in PyCharm · Open File > Settings > Project from the PyCharm menu. · Select...
Read more >
Unable to use azure SDK in Python
However, you got the error in Import Error: No module named <package-name> when you run the code import <package-name> or from ...
Read more >
Modulenotfounderror: no module named azure ( Solved )
Modulenotfounderror : no module named azure error comes when you have not installed the azure package on your system. The best way to...
Read more >
No module named 'azure.storage.blob' - Microsoft Q&A
Azure Functions Locally ModuleNotFoundError: No module named 'azure.storage.blob'. I have been following this tutorial ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found