azure-functions-python-worker icon indicating copy to clipboard operation
azure-functions-python-worker copied to clipboard

Support running on M1 Macs [Python]

Open FabianBruengerPexon opened this issue 4 years ago • 50 comments

Hey,

i am running into issues with python azure function under VSCode. FYI the same example I will present is working fine with JS.

Set up: Mac M1 Big Sur v11.2.1 python 3.9.1 Core Tools Version: 3.0.3284

I am following the usual workflow: func init, func new, func start. When I start the function, this is what I get:

Found Python version 3.9.1 (python3).

Azure Functions Core Tools
Core Tools Version:       3.0.3284 Commit hash: 98bc25e668274edd175a1647fe5a9bc4ffb6887d 
Function Runtime Version: 3.0.15371.0

Ä2021-02-16T20:28:10.779ZÅ Traceback (most recent call last):
Ä2021-02-16T20:28:10.783ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/worker.py", line 84, in <module>
Ä2021-02-16T20:28:10.783ZÅ     from azure_functions_worker import main
Ä2021-02-16T20:28:10.783ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/azure_functions_worker/main.py", line 8, in <module>
Ä2021-02-16T20:28:10.783ZÅ     from . import dispatcher
Ä2021-02-16T20:28:10.783ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/azure_functions_worker/dispatcher.py", line 21, in <module>
Ä2021-02-16T20:28:10.783ZÅ     import grpc
Ä2021-02-16T20:28:10.783ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/__init__.py", line 23, in <module>
Ä2021-02-16T20:28:10.783ZÅ     from grpc._cython import cygrpc as _cygrpc
Ä2021-02-16T20:28:10.784ZÅ ImportError: dlopen(/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so, 2): no suitable image found.  Did find:
Ä2021-02-16T20:28:10.785ZÅ  /opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so: mach-o, but wrong architecture
Ä2021-02-16T20:28:10.788ZÅ  /opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so: mach-o, but wrong architecture
Ä2021-02-16T20:28:10.788ZÅ Traceback (most recent call last):
Ä2021-02-16T20:28:10.788ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/worker.py", line 84, in <module>
Ä2021-02-16T20:28:10.788ZÅ     from azure_functions_worker import main
Ä2021-02-16T20:28:10.794ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/azure_functions_worker/main.py", line 8, in <module>
Ä2021-02-16T20:28:10.794ZÅ     from . import dispatcher
Ä2021-02-16T20:28:10.794ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/azure_functions_worker/dispatcher.py", line 21, in <module>
Ä2021-02-16T20:28:10.794ZÅ     import grpc
Ä2021-02-16T20:28:10.794ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/__init__.py", line 23, in <module>
Ä2021-02-16T20:28:10.799ZÅ     from grpc._cython import cygrpc as _cygrpc
Ä2021-02-16T20:28:10.799ZÅ **ImportError: dlopen(/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so, 2): no suitable image found.  Did find:**
Ä2021-02-16T20:28:10.799ZÅ  /opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so: mach-o, but wrong architecture
Ä2021-02-16T20:28:10.799ZÅ  /opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so: mach-o, but wrong architecture
Ä2021-02-16T20:28:10.799ZÅ Traceback (most recent call last):
Ä2021-02-16T20:28:10.800ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/worker.py", line 84, in <module>
Ä2021-02-16T20:28:10.800ZÅ     from azure_functions_worker import main
Ä2021-02-16T20:28:10.800ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/azure_functions_worker/main.py", line 8, in <module>
Ä2021-02-16T20:28:10.800ZÅ     from . import dispatcher
Ä2021-02-16T20:28:10.800ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/azure_functions_worker/dispatcher.py", line 21, in <module>
Ä2021-02-16T20:28:10.800ZÅ     import grpc
Ä2021-02-16T20:28:10.800ZÅ   File "/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/__init__.py", line 23, in <module>
Ä2021-02-16T20:28:10.800ZÅ     from grpc._cython import cygrpc as _cygrpc
Ä2021-02-16T20:28:10.800ZÅ **ImportError: dlopen(/opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so, 2): no suitable image found.  Did find:**
Ä2021-02-16T20:28:10.800ZÅ  /opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so: mach-o, but wrong architecture
Ä2021-02-16T20:28:10.801ZÅ Exceeded language worker restart retry count for runtime:python. Shutting down and proactively recycling the Functions Host to recover
Ä2021-02-16T20:28:10.808ZÅ  /opt/homebrew/Cellar/azure-functions-core-toolsÉ3/3.0.3284/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so: mach-o, but wrong architecture

Functions:

 HttpTrigger: ÄGET,POSTÅ http://localhost:7071/api/HttpTrigger

For detailed output, run func with --verbose flag.

I would appreciate some advice here! Thanks and all the best

FabianBruengerPexon avatar Feb 16 '21 20:02 FabianBruengerPexon

@FabianBruengerPexon we are waiting to get the machine to be able to test this.

apawast avatar Mar 02 '21 18:03 apawast

I'm also seeing this on M1 Mac Mini running: Python 3.9.2 Core Tools Version: 3.0.3477 Commit hash: 5fbb9a76fc00e4168f2cc90d6ff0afe5373afc6d (64-bit) Function Runtime Version: 3.0.15584.0

isa56k avatar May 25 '21 17:05 isa56k

Also experiencing this issue. Please see https://github.com/Azure/azure-functions-core-tools/issues/2680

Returning M1 Macbook, sadly, as this issue has clearly been rumbling on for many months!

simon-tarr avatar Aug 09 '21 14:08 simon-tarr

Still experiencing this on M1 MacBook Pro, Python 3.9.7, Core Tools 3.0.3785.

jamwil avatar Oct 15 '21 18:10 jamwil

The issue is still present. M1 MacBook Pro

Core Tools Version: 4.0.3780 Commit hash: 2b9e0e618f69993ff119009e48587b67ac85450e (64-bit) Function Runtime Version: 4.0.0.16394

ImportError: dlopen(/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.3780/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.3780/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)

lks-hrsch avatar Oct 27 '21 06:10 lks-hrsch

The issue is still present. M1 MacBook Pro

Core Tools Version: 4.0.3780 Commit hash: 2b9e0e6 (64-bit) Function Runtime Version: 4.0.0.16394

ImportError: dlopen(/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.3780/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.3780/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)

Still got the exact same error. Running two macbooks for this right now, waiting to solve this problem. Lets hope it comes quick in some way.

boring-joey avatar Oct 29 '21 20:10 boring-joey

Looks like Core Tools is able to run in x64 emulation but it’s starting the python worker in ARM. The worker uses x64 binaries in some places and that’s where it appears to be failing. Are you able to run the entire stack with x64 emulation? I only have an Intel Mac so I can’t try this out.

/cc @vrdmr

anthonychu avatar Oct 30 '21 07:10 anthonychu

For Node.js we were able to fix this by using a pure JS implementation of gRPC that doesn’t rely on platform specific binaries. Not sure if same exists for Python. https://github.com/Azure/azure-functions-nodejs-worker/issues/386

anthonychu avatar Oct 30 '21 07:10 anthonychu

Unable to test this at present but (thinking out loud here): I'm wondering if running everything in a conda environment of some description would help in the interim? Using conda environments has solved a ton of (unrelated) problems for me over the past few months while x86 and arm64 code is living side by side.

simon-tarr avatar Nov 02 '21 18:11 simon-tarr

Looks like Core Tools is able to run in x64 emulation but it’s starting the python worker in ARM. The worker uses x64 binaries in some places and that’s where it appears to be failing. Are you able to run the entire stack with x64 emulation? I only have an Intel Mac so I can’t try this out.

/cc @vrdmr

This was a good hint, thank you! I was able to start func start host without an error on my M1 Macbook Pro.

What have I done?

  1. Enable Rosetta in iTerm so that you get the following output:

$ arch i386

  1. install the intel homebrew with:

$ arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

refer to https://stackoverflow.com/questions/64882584/how-to-run-the-homebrew-installer-under-rosetta-2-on-m1-macbook 3. install azure-functions-core-tools@4 and python in this homebrew 4. setting python path to the rosetta python 5. run the command:

$ arch -x86_64 /usr/local/bin/func start host

lks-hrsch avatar Nov 10 '21 20:11 lks-hrsch

Cleaning up M1 Mac issues at the moment. This one seemed like the most detailed Python issue, so I've transferred it here to track any Python-specific work. Main core tools issue is here: https://github.com/Azure/azure-functions-core-tools/issues/2834

Also this comment from @vrdmr seems particularly relevant: https://github.com/Azure/azure-functions-core-tools/issues/2394#issuecomment-765056678

ejizba avatar Nov 18 '21 19:11 ejizba

Also experiencing this issue.

M1 Macbook Pro Python 3.9.4 Core Tools Version: 4.0.3971

ImportError: dlopen(/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.3971/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.3971/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)

ericdwkim avatar Dec 29 '21 14:12 ericdwkim

Fyi @vrdmr I've created an arm64 build of core tools and I now see this error when running on an M1 Mac:

Failed to initialize worker provider for: /Users/erijiz/tools/func-arm/workers/python Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.

I believe that's because Arm64 is not listed in the worker config here. Let me know when you have an arm64 build of the worker and I'd be happy to test for you.

ejizba avatar Feb 04 '22 22:02 ejizba

Running into the same issue as @ericdwkim. Also noted that this works with python 3.8 environments, but not with python 3.9. Is there an ETA for the fix @ejizba?

felixnext avatar Mar 21 '22 08:03 felixnext

The best work around I have found is to use python interpreter installed in conda environment

1. Create a conda environment with supported python version

2. Go to the root directory of the project

3. Remove .venv folder

4. Activate the newly created conda environment

5. Create new virtual environment using `python -m venv .venv/`

@felixnext

yugyesh avatar Mar 23 '22 08:03 yugyesh

For the wary traveller, I have tried a bunch of these without success and wasn't willing to switch to x86, this trick, while maybe bad practice, worked for me (basically copying over the binary): https://github.com/Azure/azure-functions-core-tools/issues/2834#issuecomment-1095566026

kentongray avatar Apr 11 '22 21:04 kentongray

Any updates on this? Silver lining is it's forced me to write more testing harnesses 😬 , but it's getting a little tricky to troubleshoot in some scenarios..

tkutcher avatar May 12 '22 02:05 tkutcher

Hi, this issue should be resolved with the release of support for Python 3.10 in Functions, which is planned for end of May.

shreyabatra4 avatar May 12 '22 19:05 shreyabatra4

Hi @shreyabatra4 Do you maybe have any info on estimated release date for Function App Python3.10 support?

kijewskimateusz avatar Jun 05 '22 11:06 kijewskimateusz

^I have the same question

danielw1534 avatar Jun 07 '22 16:06 danielw1534

@danielw1534 In the meantime you can try this workaround

kijewskimateusz avatar Jun 07 '22 17:06 kijewskimateusz

Is this fixed? non of the workaround works for me

BadrElfarri avatar Jun 10 '22 07:06 BadrElfarri

None of the work arounds work for me either. Using python3.9.12, and am getting this error:

[2022-06-10T07:46:31.695Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4544/workers/python
[2022-06-10T07:46:31.703Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.
[2022-06-10T07:46:51.637Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4544/workers/python
[2022-06-10T07:46:51.637Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.
[2022-06-10T07:46:51.783Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4544/workers/python
[2022-06-10T07:46:51.783Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.
[2022-06-10T07:46:51.806Z] A host error has occurred during startup operation 'cee605e7-7298-4408-97ec-80de3079f5f8'.
[2022-06-10T07:46:51.806Z] Microsoft.Azure.WebJobs.Script: Did not find functions with language [python].
[2022-06-10T07:46:51.817Z] Failed to stop host instance '14c8f2b6-2dc1-4e43-a8bb-b41a92c74d00'.
[2022-06-10T07:46:51.817Z] Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')

For:

Found Python version 3.9.12 (python3).

Azure Functions Core Tools
Core Tools Version:       4.0.4544 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.3.2.18186

You don't have the right version. Follow the instructions exactly.

reubano avatar Jun 10 '22 13:06 reubano

Oh thank you, I have downgraded my core tools to 4.0.4483 and it works now! I didn't notice that I was on the latest version.

Had to install NPM v14.17.6 by going to application folder->Terminal->RightClick->Select Open using Rosetta->Close and open terminal. After that installed NPM v14.17.6 using NVM...... Further followed reubano steps, works now. Thanks :)

BadrElfarri avatar Jun 10 '22 19:06 BadrElfarri

Hello, Any news about this issue? I follow the workaround mentioned in: https://github.com/Azure/azure-functions-core-tools/issues/2834#issuecomment-1136311048 to install [email protected] with npm. And I also follow this instruction to install custom Node version of 14.17.6. But I still can't run azure function locally. I've tried to run with func cli & vscode, but both of them doesn't work, without any error message. (i.e. when I type func start, it returns empty) Here is informations of my machine: MacOs Monterey v12.4 Screenshot 2022-07-13 at 13 23 11

Thanks for your help!

AJ1058310 avatar Jun 27 '22 12:06 AJ1058310

Is there any progress here? I am also facing the same issue after following the work-arounds. func start returns empty for me too.

weekend-technophile avatar Jul 04 '22 00:07 weekend-technophile

@reubano workaround worked for me, using mac m1 pro Node: v14.17.6 npm: 6.14.15 Python 3.9.13 pip 22.1.1

tonmanayo avatar Jul 12 '22 09:07 tonmanayo

@reubano workaround worked for me, using mac m1 pro Node: v14.17.6 npm: 6.14.15 Python 3.9.13 pip 22.1.1

Hello @tonmanayo , which workarround works for you? As what I mentioned here: https://github.com/Azure/azure-functions-python-worker/issues/915#issuecomment-1167272017. I followed this instruction, but it doesn't work.

AJ1058310 avatar Jul 13 '22 11:07 AJ1058310