Azure function not running on M1
Question:
Running
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
in vscode
pyenv shell 3.9.12
Requirement already satisfied: azure-functions in ./.venv/lib/python3.9/site-packages (from -r requirements.txt (line 5)) (1.12.0)
WARNING: You are using pip version 21.2.4; however, version 22.3 is available.
You should consider upgrading via the '/Users/deniz/Library/CloudStorage/OneDrive-DualCitizen/Dev/2ndfunction/.venv/bin/python -m pip install --upgrade pip' command.
* Terminal will be reused by tasks, press any key to close it.
* Executing task: . .venv/bin/activate && func host start
Found Python version 3.9.10 (python3).
Azure Functions Core Tools
Core Tools Version: 4.0.4829 Commit hash: N/A (64-bit)
Function Runtime Version: 4.11.2.19273
[2022-10-23T09:38:17.290Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4829/workers/python
[2022-10-23T09:38:17.290Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.
[2022-10-23T09:38:17.818Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4829/workers/python
[2022-10-23T09:38:17.818Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.
[2022-10-23T09:38:17.957Z] A host error has occurred during startup operation '29ac434c-0276-4c0b-a85f-c9e4863577dc'.
[2022-10-23T09:38:17.957Z] Microsoft.Azure.WebJobs.Script: Did not find functions with language [python].
[2022-10-23T09:38:17.964Z] Failed to stop host instance '3d492f60-0fd3-48dd-bce0-d7cc99da71c8'.
[2022-10-23T09:38:17.964Z] Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')
[2022-10-23T09:38:17.986Z] A host error has occurred during startup operation '1327f3e2-25e9-4318-bfea-0bac013aff02'.
[2022-10-23T09:38:17.986Z] Microsoft.Extensions.DependencyInjection: Cannot access a disposed object.
[2022-10-23T09:38:17.986Z] Object name: 'IServiceProvider'.
* Terminal will be reused by tasks, press any key to close it.
I tried a bunch of things incl:
- Create a conda environment with supported python version
- Go to the root directory of the project, Remove .venv folder
- Activate the newly created conda environment
- Create new virtual environment using
python3 -m venv .venv/
I also tried to apply the Rosetta fix as outlined here How to run the Homebrew installer under Rosetta 2 on M1 Macbook
but wasn’t successfull. How can I fix this?
Answers:
I kept running into problems with python on my M1 Mac until I went completely to Rosetta on the command line. For that, I did the following:
- Update Rosetta:
In a Terminal type:
softwareupdate --install-rosetta
- In Finder, type ⇧⌘G and go to /Applications/Utilities. Then duplicate Terminal:
- Rename the second Terminal to "Rosetta" (or whatever you like) and have it execute in Rosetta by checking "Open using Rosetta" in the "Get Info" dialogue:
- Open a Rosetta Terminal and make sure it shows
i386
when you issue the command arch
:
- In that terminal, install homebrew (per the homebrew homepage):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Once homebrew has been installed, install miniconda using homebrew:
brew install --cask miniconda
- Create a conda environment, for instance here a python 3.9 env named
azure
:
conda create -n azure python=3.9
Then activate the environment:
conda activate azure
From here on out, you have a fully functioning i386 Python system. This has resolved all problems that I had with Azure, Numpy, Pandas, etc. on my M1 Mac.
I faced the same issue in my Mac. Thanks, Daniel for your solution, it helps me partially. To achieve a final result, I followed this article and at the end I can start my Azure Functions locally. Here is the link to post: https://medium.com/mkdir-awesome/how-to-install-x86-64-homebrew-packages-on-apple-m1-macbook-54ba295230f
Running
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
in vscode
pyenv shell 3.9.12
Requirement already satisfied: azure-functions in ./.venv/lib/python3.9/site-packages (from -r requirements.txt (line 5)) (1.12.0)
WARNING: You are using pip version 21.2.4; however, version 22.3 is available.
You should consider upgrading via the '/Users/deniz/Library/CloudStorage/OneDrive-DualCitizen/Dev/2ndfunction/.venv/bin/python -m pip install --upgrade pip' command.
* Terminal will be reused by tasks, press any key to close it.
* Executing task: . .venv/bin/activate && func host start
Found Python version 3.9.10 (python3).
Azure Functions Core Tools
Core Tools Version: 4.0.4829 Commit hash: N/A (64-bit)
Function Runtime Version: 4.11.2.19273
[2022-10-23T09:38:17.290Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4829/workers/python
[2022-10-23T09:38:17.290Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.
[2022-10-23T09:38:17.818Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4829/workers/python
[2022-10-23T09:38:17.818Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.
[2022-10-23T09:38:17.957Z] A host error has occurred during startup operation '29ac434c-0276-4c0b-a85f-c9e4863577dc'.
[2022-10-23T09:38:17.957Z] Microsoft.Azure.WebJobs.Script: Did not find functions with language [python].
[2022-10-23T09:38:17.964Z] Failed to stop host instance '3d492f60-0fd3-48dd-bce0-d7cc99da71c8'.
[2022-10-23T09:38:17.964Z] Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')
[2022-10-23T09:38:17.986Z] A host error has occurred during startup operation '1327f3e2-25e9-4318-bfea-0bac013aff02'.
[2022-10-23T09:38:17.986Z] Microsoft.Extensions.DependencyInjection: Cannot access a disposed object.
[2022-10-23T09:38:17.986Z] Object name: 'IServiceProvider'.
* Terminal will be reused by tasks, press any key to close it.
I tried a bunch of things incl:
- Create a conda environment with supported python version
- Go to the root directory of the project, Remove .venv folder
- Activate the newly created conda environment
- Create new virtual environment using
python3 -m venv .venv/
I also tried to apply the Rosetta fix as outlined here How to run the Homebrew installer under Rosetta 2 on M1 Macbook
but wasn’t successfull. How can I fix this?
I kept running into problems with python on my M1 Mac until I went completely to Rosetta on the command line. For that, I did the following:
- Update Rosetta:
In a Terminal type:
softwareupdate --install-rosetta
- In Finder, type ⇧⌘G and go to /Applications/Utilities. Then duplicate Terminal:
- Rename the second Terminal to "Rosetta" (or whatever you like) and have it execute in Rosetta by checking "Open using Rosetta" in the "Get Info" dialogue:
- Open a Rosetta Terminal and make sure it shows
i386
when you issue the commandarch
:
- In that terminal, install homebrew (per the homebrew homepage):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Once homebrew has been installed, install miniconda using homebrew:
brew install --cask miniconda
- Create a conda environment, for instance here a python 3.9 env named
azure
:
conda create -n azure python=3.9
Then activate the environment:
conda activate azure
From here on out, you have a fully functioning i386 Python system. This has resolved all problems that I had with Azure, Numpy, Pandas, etc. on my M1 Mac.
I faced the same issue in my Mac. Thanks, Daniel for your solution, it helps me partially. To achieve a final result, I followed this article and at the end I can start my Azure Functions locally. Here is the link to post: https://medium.com/mkdir-awesome/how-to-install-x86-64-homebrew-packages-on-apple-m1-macbook-54ba295230f