[Fixed] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python (issue on Mac M1 Chip) – Python

by
Ali Hasan
azure-active-directory azure-functions flask-sqlalchemy llama-cpp-python

Quick Fix: Modify the paths to your homebrew azure function folder (mine is currently on 4.0.5198 where-as the instructions are for 4.0.4915).

You’ll also need to repeat these steps when ever the homebrew recipe updates for Azure Functions.

The Problem:

I am unable to run Azure functions with Python on my MacBook Pro with an M1 chip, which uses Arm64 architecture. Azure function Core tools does not support Python function development on Arm64 devices, requiring emulation in an x86 environment. I have followed online instructions to set up Rosetta, Homebrew, and the Azure Functions Core Tools, including configuring my .zshrc file and host.json settings. However, I receive an error when running ‘func host start’ in the Rosetta terminal: ‘Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.’

The Solutions:

Solution 1: Modify Path in Homebrew Azure Function Folder

Modify the path in the Homebrew Azure function folder to make it compatible with your system’s architecture. Here’s a step-by-step guide:

  1. Locate the Homebrew Azure function folder. By default, it’s located at /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5198.
  2. Open the file python/worker/provider_siteconfig.py located in the folder.
  3. Find the following line:
    AZURE_FUNCTIONS_WORKER_PYTHON_IMAGE = 'mcr.microsoft.com/azure-functions/python:4-amd64'
    
  4. Replace amd64 with arm64. The line should now look like this:
    AZURE_FUNCTIONS_WORKER_PYTHON_IMAGE = 'mcr.microsoft.com/azure-functions/python:4-arm64'
    
  5. Save the file.

This modification will instruct Azure Functions Core Tools to use the ARM64 version of the Python image, resolving the architecture incompatibility issue.

Remember to repeat these steps whenever the Homebrew recipe for Azure Functions updates.

Solution 2: Check Python Executable Path

Verify that the host.json file contains the correct Python executable path in the languageWorkers:python:pythonPath setting. Ensure that the path is set to the Python executable corresponding to the emulated x86 environment on your M1 Mac. You can use the archcheck function, as provided in the GitHub article, to detect the architecture automatically and set the appropriate path.

Solution 3: Updating VSCode Settings

To resolve the issue with running Azure functions with Python on an M1 Mac, add the following setting to your VSCode settings.json file:

"azureFunctions.funcCliPath": "/usr/local/Cellar/azure-functions-core-tools@4/4.0.5095/func"

This setting specifies the path to the Azure Functions Core Tools executable, ensuring that the correct version is used when running functions.

Q&A

How to detect and run the correct architecture (ARM or x86_64) for Azure functions on M1 Mac

You can use the following code in your .zshrc file to automatically detect the architecture and run the correct commands:

archcheck () {
   if [ "$(uname -p)" = "i386" ]; then
     echo "Running in i386 mode (Rosetta)"
     eval "$(/usr/local/homebrew/bin/brew shellenv)"
     alias brew='/usr/local/homebrew/bin/brew'  # not sure aliases will set from within a function
   elif
     echo "Running in ARM mode (M1)"
     eval "$(/opt/homebrew/bin/brew shellenv)"
     alias brew='/opt/homebrew/bin/brew'  # not sure aliases will set from within a function
   else
     echo "Unknown architecture detected: $(uname -p) // $(arch)"
   fi
}
alias native="arch -arm64 zsh && archcheck"
alias rosetta="arch -x86_64 zsh && archcheck"