Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ModuleNotFoundError: No module named 'azure.storage'. Azure Function

I am trying to use an Azure Function to generate a SAS token. The import statement is failing.

import azure.functions as func
from azure.storage.blob import generate_container_sas

with

Exception: ModuleNotFoundError: No module named 'azure.storage'. 
Troubleshooting Guide: https://aka.ms/functions-modulenotfound
Stack:   File "C:Program FilesMicrosoftAzure Functions Core 
Toolsworkerspython3.8WINDOWSX64azure_functions_worker 
dispatcher.py", line 266, in _handle__function_load_request
func = loader.load_function(
File "C:Program FilesMicrosoftAzure Functions Core 
Toolsworkerspython3.8WINDOWSX64azure_functions_workerutils 
wrappers.py", line 34, in call
raise extend_exception_message(e, message)
File "C:Program FilesMicrosoftAzure Functions Core 
Toolsworkerspython3.8WINDOWSX64azure_functions_workerutils 
wrappers.py", line 32, in call
return func(*args, **kwargs)
File "C:Program FilesMicrosoftAzure Functions Core 
Toolsworkerspython3.8WINDOWSX64azure_functions_worker 
loader.py", line 76, in load_function
mod = importlib.import_module(fullmodname)
File "C:Users2259252AppDataLocalProgramsPythonPython38lib 
importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:ProjectsAdditiveSkyforgeAPIFileAPIRequestFileUpload 
__init__.py", line 4, in <module>
from azure.storage.blob import generate_container_sas.

Package is installed in the venv

$ .venv/Scripts/python -m pip freeze
azure-core==1.9.0
azure-functions==1.5.0
azure-storage-blob==12.6.0
...

My requirements.txt file:

azure-functions
azure-storage-blob==12.6.0

What am I missing?

Closest question

question from:https://stackoverflow.com/questions/65643865/modulenotfounderror-no-module-named-azure-storage-azure-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From you description, it seems you are based on global environment instead of running in .venv environment.

Please pay attention to this:

enter image description here

If you are based on Windows OS, then I think you need to use below command:

cd .venv

then

.Scriptsactivate.bat

After all, run

cd ..

func host start

After that, It works fine on my side.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...