EEEEH
EEEEH

Reputation: 779

Local hosting python azure function fail with M1

As title, I want to host azure function in local with VSCode but something error.

host.json:

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

local.setting.json:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": ""
  }
}

Error Message:

Functions:

        HttpTrigger1: [GET,POST] http://localhost:7071/api/HttpTrigger1

For detailed output, run func with --verbose flag.
....
[2022-05-09T06:52:10.300Z]     from . import dispatcher
[2022-05-09T06:52:10.300Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4483/workers/python/3.9/OSX/X64/azure_functions_worker/dispatcher.py", line 19, in <module>
[2022-05-09T06:52:10.300Z]     import grpc
[2022-05-09T06:52:10.300Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4483/workers/python/3.9/OSX/X64/grpc/__init__.py", line 23, in <module>
[2022-05-09T06:52:10.300Z]     from grpc._cython import cygrpc as _cygrpc
[2022-05-09T06:52:10.300Z] ImportError: dlopen(/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4483/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so, 0x0002): tried: '/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4483/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/cygrpc.cpython-39-darwin.so' (no such file), '/usr/lib/cygrpc.cpython-39-darwin.so' (no such file)
[2022-05-09T06:52:13.512Z] Host lock lease acquired by instance ID '0000000000000000000000008F1C7F2E'.

Upvotes: 2

Views: 2196

Answers (2)

Mateusz Dorobek
Mateusz Dorobek

Reputation: 761

Setting up Rosetta

  1. Open Finder, go to Applications and find Terminal.
  2. Right-click the new terminal (iTerm), and choose "Get Info."
  3. Enable "Open using Rosetta" for the new terminal.
  4. Run arch in the terminal, you should see i386 as the response.

Installing Tools

After setting up x86 emulation, install the necessary tools:

  1. Install Homebrew:
    /bin/bash -c "$(curl -fsSL  https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Install Python using Homebrew: /usr/local/bin/brew install [email protected]
  3. Install Azure Functions Core Tools:
    /usr/local/bin/brew tap azure/functions
    /usr/local/bin/brew install azure-functions-core-tools@4
    

Usage

Since you have another installation of azure-functions-core-tools, you need to specify which version you want to use. (You can create alias for that)

/usr/local/Cellar/azure-functions-core-tools@4/4.0.4915/func host start

More detailed instruction in Running python azure function locally on an M1 M2 macOS ~ Issam Ben

Upvotes: 0

SwethaKandikonda
SwethaKandikonda

Reputation: 8252

After reproducing from our end we observed that If you have an arm64 Python, it'll never be able to load an x86_64 shared library hence we need to enable Rosetta which works at a process by process level.

Steps to be followed

  1. Check the Rosetta in iTerm.
  2. Install homebrew, azure functions core tools, and python in the current homebrew.
  3. And then run your azure function.

REFERENCES: Support running on M1 Macs [Python]

Upvotes: 2

Related Questions