skip to Main Content

My laptop is MacBook Pro (16-inch, 2021) Apple M1 Max.

I want to run Azure function with Python.

Currently, Azure function Core tools does not support Python function development on ARM64 devices. To develop Python functions on a Mac with an M1 chip, you must run in an emulated x86 environment. To learn more, see x86 emulation on ARM64.

I already followed the instruction.

Install the Azure Functions Core Tools

So far, I did:

  1. install Homebrew

  2. Open terminal using Rosetta.

  3. Also Enable emulation in Visual Studio Code

  4. setting.json

    "azureFunctions.deploySubpath": ".",
    "azureFunctions.scmDoBuildDuringDeployment": true,
    "azureFunctions.pythonVenv": ".venv",
    "azureFunctions.projectLanguage": "Python",
    "azureFunctions.projectRuntime": "~4",
    "debug.internalConsoleOptions": "neverOpen",
    "terminal.integrated.profiles.osx": {
       "rosetta": {
         "path": "arch",
         "args": ["-x86_64", "zsh", "-l"],
         "overrideName": true
       }
     }
}
  1. I have .zshrc file in the root folder which my project located.
# rosetta terminal setup
if [ $(arch) = "i386" ]; then
    alias python="/usr/local/bin/python3"
    alias brew86='/usr/local/bin/brew'
    alias pyenv86="arch -x86_64 pyenv"
    alias func="/usr/local/Cellar/azure-functions-core-tools@4/4.0.5095/func"
fi

so in VS code editor, I have rosetta terminal. run arch will show i386 which emulate ARM64.

  1. copy azure-functions-core-tools@4/4.0.5095 folder from opt/homebrew/Cellar/azure-functions-core-tools@4 past to /usr/local/Cellar/azure-functions-core-tools@4/4.0.5095/func" because if I install azure-functions-core-tools@4 from terminal, it always goes to homebrew folder.

If run func host start in Rosetta terminal, it showed error that

Failed to initialize worker provider for: /usr/local/Cellar/azure-functions-core-tools@4/4.0.5095/workers/python

Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.
Failed to initialize worker provider for: /usr/local/Cellar/azure-functions-core-tools@4/4.0.5095/workers/python……(skip)

I already follow any solution from online, most are this way to run azure function on M1 Chip.

Is there any wrong I did or something I missing?

4/13 update
host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  }
}

2

Answers


  1. Failed to initialize worker provider for: /usr/local/Cellar/azure-functions-core-tools@4/4.0.5095/workers/python

    All the tools you have installed are correct and once again check the Azure Functions core tools, Python version is installed properly.

    Check the host.json file to check the Python executable path is given properly with the setting of languageWorkers:python:pythonPath

    I know that Microsoft explicitly mentioned that Functions (Python) not supported on ARM64 devices but emulated x86 environment is the provided alternative.

    Give the both architectures code in the zsh environment so that it detects automatically and runs in that environment as shown in this GitHub Article.

    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"

    If still not yet resolved, you can raise the issue in the official forum of Azure Functions Host in GitHub by providing your environment and the issue details.

    Login or Signup to reply.
  2. Try add this new setting on your .vscode/settings.json

    "azureFunctions.funcCliPath": "/usr/local/Cellar/azure-functions-core-tools@4/4.0.5095/func"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search