Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
335 stars 103 forks source link

Support running on M1 Macs [Python] #915

Closed FabianBruengerPexon closed 11 months ago

FabianBruengerPexon commented 3 years ago

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

apawast commented 3 years ago

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

isa56k commented 3 years ago

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

simon-tarr commented 3 years ago

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!

jamwil commented 3 years ago

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

lks-hrsch commented 3 years ago

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)

boring-joey commented 3 years ago

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.

anthonychu commented 3 years ago

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 commented 3 years ago

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

simon-tarr commented 3 years ago

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.

lks-hrsch commented 2 years ago

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

  2. 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

  1. install azure-functions-core-tools@4 and python in this homebrew
  2. setting python path to the rosetta python
  3. run the command:

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

ejizba commented 2 years ago

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

ericdwkim commented 2 years ago

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)

ejizba commented 2 years ago

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.

felixnext commented 2 years ago

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?

yugyesh commented 2 years ago

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

kentongray commented 2 years ago

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

tkutcher commented 2 years ago

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..

shreyabatra4 commented 2 years ago

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

kijewskimateusz commented 2 years ago

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

0xdubs commented 2 years ago

^I have the same question

kijewskimateusz commented 2 years ago

@danielw1534 In the meantime you can try this workaround

BadrElfarri commented 2 years ago

Is this fixed? non of the workaround works for me

vamshiaruru-virgodesigns commented 2 years ago

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
reubano commented 2 years ago

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

vamshiaruru-virgodesigns commented 2 years ago

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.

BadrElfarri commented 2 years ago

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 :)

AJ1058310 commented 2 years ago

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 azure-functions-core-tools@4.0.4483 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!

weekend-technophile commented 2 years ago

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

tonmanayo commented 2 years ago

@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

AJ1058310 commented 2 years ago

@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.

tonmanayo commented 2 years ago

@AJ1058310 This one https://github.com/Azure/azure-functions-python-worker/issues/915#issuecomment-1152344417

I uninstalled python from brew, re-installed it with that version and also used nvm to switch to the correct node version, then used npm to install core tools and did the copy.

After doing the cp of cygrpc.cpython-39-darwin.so func started working for me

Also remember to use a new terminal after installing, use which func or which python to see which bin is being used

edgarhuichen commented 2 years ago

I am able to get func start work by following the your steps but somehow func is launched in the homebrew python env instead of conda env. As a result, I get module not found error

@AJ1058310 This one #915 (comment)

I uninstalled python from brew, re-installed it with that version and also used nvm to switch to the correct node version, then used npm to install core tools and did the copy.

After doing the cp of cygrpc.cpython-39-darwin.so func started working for me

Also remember to use a new terminal after installing, use which func or which python to see which bin is being used

edgarhuichen commented 2 years ago

I think it's good to mention you should also create a venv from the homebrew installed python. Otherwise, you will run into errors in relation to import

lucafrost commented 2 years ago

Workaround on Apple Silicon

1. Installing Rosetta

  1. Run the following command in terminal: softwareupdate --install-rosetta --agree-to-license
    • This will install Apple's Rosetta which emulates x64_86 architecture.
  2. Navigate to ~/Applications/ and duplicate 'Terminal'
    • You may wish to rename the duplicate "Rosetta Terminal"
  3. Secondary-click your new terminal, navigate to 'Get Info', and check the 'Open using Rosetta' box.

You have now created a second terminal application that will always run as x64_86. Test this by entering arch, it should show as i386 as opposed to arm64. You can always enter python -c "import platform;print(platform.machine())" to test that the Python interpreter is running on Rosetta.

The two terminals share the same preferences (i.e. theme), so using a new icon for the Rosetta terminal is advised. The process for replacing an application icon is well documented online. A high-fidelity image of the Apple Rosetta logo can be found here

2. Installing Dependencies

  1. Install the intel arch for brew: arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

    • Good practice to run echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/USERNAME/.zprofile and eval "$(/usr/local/bin/brew shellenv)" after brew install
  2. Create a new Conda env (named rosetta): CONDA_SUBDIR=osx-64 conda create -n rosetta python=3.9

    ⚠️ Python 3.9.X is the latest version supported by Azure CLI & Funcs

  3. Activate new Conda env: conda activate rosetta

  4. Install Azure Functions Core Tools by running arch -x86_64 brew tap azure/functions then arch -x86_64 brew install azure-functions-core-tools@4

  5. Install Azure CLI: arch -x86_64 brew update && arch -x86_64 brew install azure-cli

  6. Run az login to authenticate in browser.

    • You should see something like the following...
      [
      {
      "cloudName": "AzureCloud",
      "homeTenantId": "a000000-b000-c000-d000-e00000000000",
      "id": "a000000-b000-c000-d000-e00000000000",
      "isDefault": true,
      "managedByTenants": [],
      "name": "Pay-As-You-Go",
      "state": "Enabled",
      "tenantId": "a000000-b000-c000-d000-e00000000000",
      "user": {
        "name": "first.last@example.com",
        "type": "user"
      }
      }
      ]
  7. Navigate to the project directory & run pip install -r requirements.txt

    3. Testing that all is A-OK

  8. Start the app: Azure already knows that the directory contains a function app. You do not need to initiate a new function app, simply run func start host

    • Your endpoint should be localhost:7071...
    • There is no authentication 👋 Goodbye Ocp-Apim-Subscription-Key
    • Should the above perform as expected, you're off... Happy Coding 🤖🚀
AJ1058310 commented 2 years ago

The workaround of lucafrost works for me 🎉 P.S. In my case, before "8. Navigate to the project directory & run pip install -r requirements.txt", I need to create a .venv(as what edgarhuichen mentioned here), otherwise you will get some ModuleNotFoundError...

python -m venv .venv
source .venv/bin/activate
pip3 install virtualenv
.venv/bin/python -m pip install --upgrade pip
pip install -r requirements.txt

​​​​​

lucafrost commented 2 years ago

@AJ1058310 glad my workaround helped — in response to your need to create a .venv, did conda not take care of all of that for you? Only asking as I will amend my post if it's lacking in some way

AJ1058310 commented 2 years ago

@AJ1058310 glad my workaround helped — in response to your need to create a .venv, did conda not take care of all of that for you? Only asking as I will amend my post if it's lacking in some way

@lucafrost Yes, I do need to create a .venv in my case. I tried with conda before, even if all "missing" modules are installed in conda env and I run func start host in the activated conda env, it doesn't work. Maybe, there is some other configs to tell azfn take conda in place of .venv?

AaronM44 commented 2 years ago

How long until official support for m1 macs is released?

shreyabatra4 commented 2 years ago

Hi, due to an internal platform upgrade, the release of Python 3.10 has been delayed to September 31. Support for M1 Macs will also be available upon the release. I will keep this thread posted on any new updates. Thanks a lot for your patience while we get this resolved.

austingayler commented 2 years ago

Workaround on Apple Silicon

1. Installing Rosetta

   .......

   * Your endpoint should be `localhost:7071...`
   * There is no authentication 👋 Goodbye `Ocp-Apim-Subscription-Key`
   * Should the above perform as expected, you're off... Happy Coding 🤖🚀

Is this working correctly insider docker for anyone?

RobertPaulson90 commented 2 years ago

@lucafrost your guide helped me immensely and I managed to get it all working. Using conda, not venv. I didn't need to do anything extra for VS Code to work either, so I can attach and debug with breakpoints. Look forward to official arm64 support in the future - guessing we lose some performance running in emulator mode. But hey, at least it's working =)

edit: scratch that. I actually did need venv like @AJ1058310 suggested. Only using conda I still got the arm64 error

adradr commented 2 years ago

I have been successfully start using the combination of steps mentioned above:

# Install Python
brew install python@3.9

# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

# Update/check your source files (.zshrc, .bashrc, etc.)
export PATH="~/.nvm/current/bin:$PATH"

# Install specific Node version
nvm install 14.17.6

Then I had to create a conda env and use that:

# Create new conda env
conda create -n azure-env python=3.9.13
conda activate azure-env

# Install grpcio
pip install grpcio

# Create the .venv in the project ROOT

# Now finally install npm package for azure functions
npm install azure-functions-core-tools@4.0.4483

# Do the linking with the conda env path
cp ~/miniforge3/envs/azure-env/lib/python3.9/site-packages/grpc/_cython/cygrpc.cpython-39-darwin.so ~/.nvm/versions/node/v14.17.6/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.9/OSX/X64/grpc/_cython/cygrpc.cpython-39-darwin.so

Acquired the following versions:

python --version
Python 3.9.13

node --version
v14.17.6

At this point I was finally able to launch the local function service with func start

(azure-env) ➜  AzureFunc git:(master) ✗ func start --verbose
Found Python version 3.9.13 (python3).

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

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

[2022-08-29T09:36:35.724Z] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '31668149-0945-4fc0-bfa3-17331381633b'
[2022-08-29T09:36:35.743Z] Reading host configuration file '/Users/adr/Desktop/AzureFunc/host.json'
[2022-08-29T09:36:35.746Z] Host configuration file read:
[2022-08-29T09:36:35.747Z] {
[2022-08-29T09:36:35.747Z]   "version": "2.0",
[2022-08-29T09:36:35.747Z]   "logging": {
[2022-08-29T09:36:35.747Z]     "applicationInsights": {
[2022-08-29T09:36:35.747Z]       "samplingSettings": {
[2022-08-29T09:36:35.747Z]         "isEnabled": true,
[2022-08-29T09:36:35.747Z]         "excludedTypes": "Request"
[2022-08-29T09:36:35.747Z]       }
[2022-08-29T09:36:35.747Z]     }
[2022-08-29T09:36:35.747Z]   },
[2022-08-29T09:36:35.747Z]   "extensionBundle": {
[2022-08-29T09:36:35.747Z]     "id": "Microsoft.Azure.Functions.ExtensionBundle",
[2022-08-29T09:36:35.747Z]     "version": "[2.*, 3.0.0)"
[2022-08-29T09:36:35.747Z]   }
[2022-08-29T09:36:35.747Z] }
[2022-08-29T09:36:35.831Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[2022-08-29T09:36:35.836Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[2022-08-29T09:36:35.836Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[2022-08-29T09:36:35.846Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at /Users/adr/.azure-functions-core-tools/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle
[2022-08-29T09:36:35.854Z] Found a matching extension bundle at /Users/adr/.azure-functions-core-tools/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/2.13.0
[2022-08-29T09:36:35.891Z] Loading functions metadata
[2022-08-29T09:36:35.896Z] Reading functions metadata
[2022-08-29T09:36:35.942Z] 1 functions found
[2022-08-29T09:36:35.967Z] 1 functions loaded
[2022-08-29T09:36:35.971Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at /Users/adr/.azure-functions-core-tools/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle
[2022-08-29T09:36:35.972Z] Found a matching extension bundle at /Users/adr/.azure-functions-core-tools/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/2.13.0
[2022-08-29T09:36:35.975Z] Fetching information on versions of extension bundle Microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/index.json
[2022-08-29T09:36:36.281Z] Skipping bundle download since it already exists at path /Users/adr/.azure-functions-core-tools/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/2.13.0
[2022-08-29T09:36:36.291Z] Loading extension bundle from /Users/adr/.azure-functions-core-tools/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/2.13.0/bin
[2022-08-29T09:36:36.291Z] Script Startup resetting load context with base path: '/Users/adr/.azure-functions-core-tools/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/2.13.0/bin'.
[2022-08-29T09:36:36.311Z] Reading host configuration file '/Users/adr/Desktop/AzureFunc/host.json'
[2022-08-29T09:36:36.312Z] Host configuration file read:
[2022-08-29T09:36:36.312Z] {
[2022-08-29T09:36:36.312Z]   "version": "2.0",
[2022-08-29T09:36:36.312Z]   "logging": {
[2022-08-29T09:36:36.312Z]     "applicationInsights": {
[2022-08-29T09:36:36.312Z]       "samplingSettings": {
[2022-08-29T09:36:36.312Z]         "isEnabled": true,
[2022-08-29T09:36:36.312Z]         "excludedTypes": "Request"
[2022-08-29T09:36:36.312Z]       }
[2022-08-29T09:36:36.312Z]     }
[2022-08-29T09:36:36.312Z]   },
[2022-08-29T09:36:36.312Z]   "extensionBundle": {
[2022-08-29T09:36:36.312Z]     "id": "Microsoft.Azure.Functions.ExtensionBundle",
[2022-08-29T09:36:36.312Z]     "version": "[2.*, 3.0.0)"
[2022-08-29T09:36:36.312Z]   }
[2022-08-29T09:36:36.312Z] }
[2022-08-29T09:36:36.804Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[2022-08-29T09:36:36.805Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[2022-08-29T09:36:36.805Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[2022-08-29T09:36:36.988Z] Initializing Warmup Extension.
[2022-08-29T09:36:37.074Z] Initializing Host. OperationId: '31668149-0945-4fc0-bfa3-17331381633b'.
[2022-08-29T09:36:37.087Z] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=31668149-0945-4fc0-bfa3-17331381633b
[2022-08-29T09:36:37.129Z] LoggerFilterOptions
[2022-08-29T09:36:37.129Z] {
[2022-08-29T09:36:37.129Z]   "MinLevel": "None",
[2022-08-29T09:36:37.129Z]   "Rules": [
[2022-08-29T09:36:37.129Z]     {
[2022-08-29T09:36:37.129Z]       "ProviderName": null,
[2022-08-29T09:36:37.129Z]       "CategoryName": null,
[2022-08-29T09:36:37.129Z]       "LogLevel": null,
[2022-08-29T09:36:37.129Z]       "Filter": "<AddFilter>b__0"
[2022-08-29T09:36:37.129Z]     },
[2022-08-29T09:36:37.129Z]     {
[2022-08-29T09:36:37.129Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2022-08-29T09:36:37.130Z]       "CategoryName": null,
[2022-08-29T09:36:37.130Z]       "LogLevel": "None",
[2022-08-29T09:36:37.130Z]       "Filter": null
[2022-08-29T09:36:37.130Z]     },
[2022-08-29T09:36:37.130Z]     {
[2022-08-29T09:36:37.130Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2022-08-29T09:36:37.130Z]       "CategoryName": null,
[2022-08-29T09:36:37.130Z]       "LogLevel": null,
[2022-08-29T09:36:37.130Z]       "Filter": "<AddFilter>b__0"
[2022-08-29T09:36:37.130Z]     },
[2022-08-29T09:36:37.130Z]     {
[2022-08-29T09:36:37.130Z]       "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2022-08-29T09:36:37.130Z]       "CategoryName": null,
[2022-08-29T09:36:37.130Z]       "LogLevel": null,
[2022-08-29T09:36:37.130Z]       "Filter": "<AddFilter>b__0"
[2022-08-29T09:36:37.130Z]     }
[2022-08-29T09:36:37.130Z]   ]
[2022-08-29T09:36:37.130Z] }
[2022-08-29T09:36:37.130Z] LoggerFilterOptions
[2022-08-29T09:36:37.131Z] {
[2022-08-29T09:36:37.131Z]   "MinLevel": "None",
[2022-08-29T09:36:37.131Z]   "Rules": [
[2022-08-29T09:36:37.131Z]     {
[2022-08-29T09:36:37.131Z]       "ProviderName": null,
[2022-08-29T09:36:37.131Z]       "CategoryName": null,
[2022-08-29T09:36:37.131Z]       "LogLevel": null,
[2022-08-29T09:36:37.131Z]       "Filter": "<AddFilter>b__0"
[2022-08-29T09:36:37.131Z]     },
[2022-08-29T09:36:37.131Z]     {
[2022-08-29T09:36:37.131Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2022-08-29T09:36:37.131Z]       "CategoryName": null,
[2022-08-29T09:36:37.131Z]       "LogLevel": "None",
[2022-08-29T09:36:37.131Z]       "Filter": null
[2022-08-29T09:36:37.131Z]     },
[2022-08-29T09:36:37.131Z]     {
[2022-08-29T09:36:37.131Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2022-08-29T09:36:37.131Z]       "CategoryName": null,
[2022-08-29T09:36:37.131Z]       "LogLevel": null,
[2022-08-29T09:36:37.131Z]       "Filter": "<AddFilter>b__0"
[2022-08-29T09:36:37.131Z]     },
[2022-08-29T09:36:37.131Z]     {
[2022-08-29T09:36:37.131Z]       "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2022-08-29T09:36:37.131Z]       "CategoryName": null,
[2022-08-29T09:36:37.131Z]       "LogLevel": null,
[2022-08-29T09:36:37.131Z]       "Filter": "<AddFilter>b__0"
[2022-08-29T09:36:37.131Z]     }
[2022-08-29T09:36:37.131Z]   ]
[2022-08-29T09:36:37.131Z] }
[2022-08-29T09:36:37.132Z] ConcurrencyOptions
[2022-08-29T09:36:37.132Z] {
[2022-08-29T09:36:37.132Z]   "DynamicConcurrencyEnabled": false,
[2022-08-29T09:36:37.132Z]   "MaximumFunctionConcurrency": 500,
[2022-08-29T09:36:37.132Z]   "CPUThreshold": 0.8,
[2022-08-29T09:36:37.132Z]   "SnapshotPersistenceEnabled": true
[2022-08-29T09:36:37.132Z] }
[2022-08-29T09:36:37.138Z] FunctionResultAggregatorOptions
[2022-08-29T09:36:37.138Z] {
[2022-08-29T09:36:37.138Z]   "BatchSize": 1000,
[2022-08-29T09:36:37.138Z]   "FlushTimeout": "00:00:30",
[2022-08-29T09:36:37.138Z]   "IsEnabled": true
[2022-08-29T09:36:37.138Z] }
[2022-08-29T09:36:37.138Z] SingletonOptions
[2022-08-29T09:36:37.138Z] {
[2022-08-29T09:36:37.138Z]   "LockPeriod": "00:00:15",
[2022-08-29T09:36:37.138Z]   "ListenerLockPeriod": "00:00:15",
[2022-08-29T09:36:37.138Z]   "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[2022-08-29T09:36:37.138Z]   "LockAcquisitionPollingInterval": "00:00:05",
[2022-08-29T09:36:37.138Z]   "ListenerLockRecoveryPollingInterval": "00:01:00"
[2022-08-29T09:36:37.138Z] }
[2022-08-29T09:36:37.143Z] Starting JobHost
[2022-08-29T09:36:37.152Z] Starting Host (HostId=macbookpro1768-779890879, InstanceId=3cf92450-211b-4457-9fb2-c0ce0866f5fc, Version=4.1.3.17473, ProcessId=32082, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
[2022-08-29T09:36:37.161Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[2022-08-29T09:36:37.161Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[2022-08-29T09:36:37.161Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[2022-08-29T09:36:37.176Z] Loading functions metadata
[2022-08-29T09:36:37.177Z] Reading functions metadata
[2022-08-29T09:36:37.179Z] 1 functions found
[2022-08-29T09:36:37.192Z] 1 functions loaded
[2022-08-29T09:36:37.286Z] Generating 1 job function(s)
[2022-08-29T09:36:37.460Z] Found the following functions:
[2022-08-29T09:36:37.460Z] Host.Functions.HttpTrigger1
[2022-08-29T09:36:37.460Z] 
[2022-08-29T09:36:37.486Z] HttpOptions
[2022-08-29T09:36:37.486Z] {
[2022-08-29T09:36:37.486Z]   "DynamicThrottlesEnabled": false,
[2022-08-29T09:36:37.486Z]   "EnableChunkedRequestBinding": false,
[2022-08-29T09:36:37.486Z]   "MaxConcurrentRequests": -1,
[2022-08-29T09:36:37.486Z]   "MaxOutstandingRequests": -1,
[2022-08-29T09:36:37.486Z]   "RoutePrefix": "api"
[2022-08-29T09:36:37.486Z] }
[2022-08-29T09:36:37.524Z] Initializing function HTTP routes
[2022-08-29T09:36:37.525Z] Mapped function route 'api/HttpTrigger1' [get,post] to 'HttpTrigger1'
[2022-08-29T09:36:37.525Z] 
[2022-08-29T09:36:37.543Z] Host initialized (371ms)
[2022-08-29T09:36:37.550Z] Host started (396ms)
[2022-08-29T09:36:37.550Z] Job host started
[2022-08-29T09:36:37.672Z] Host did not shutdown within its allotted time.

Functions:

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

[2022-08-29T09:36:39.746Z] Executing HTTP request: {
[2022-08-29T09:36:39.747Z]   requestId: "e0c86325-a5de-45b9-841e-f2a793c1e0b6",
[2022-08-29T09:36:39.747Z]   method: "GET",
[2022-08-29T09:36:39.747Z]   userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15",
[2022-08-29T09:36:39.747Z]   uri: "/api/HttpTrigger1"
[2022-08-29T09:36:39.747Z] }
[2022-08-29T09:36:40.022Z] Executing 'Functions.HttpTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=8b705c38-7bac-45d5-891b-9cce64be84bc)
[2022-08-29T09:36:42.176Z] Host lock lease acquired by instance ID '000000000000000000000000CF9C2A34'.
[2022-08-29T09:37:26.174Z] Final functionDispatcher state: WorkerProcessRestarting. Initialization timed out and host is shutting down
[2022-08-29T09:37:26.278Z] Executed 'Functions.HttpTrigger1' (Failed, Id=8b705c38-7bac-45d5-891b-9cce64be84bc, Duration=46287ms)
[2022-08-29T09:37:26.278Z] System.Private.CoreLib: Exception while executing function: Functions.HttpTrigger1. Microsoft.Azure.WebJobs.Script: Did not find any initialized language workers.
[2022-08-29T09:37:26.339Z] Executed HTTP request: {
[2022-08-29T09:37:26.339Z]   requestId: "e0c86325-a5de-45b9-841e-f2a793c1e0b6",
[2022-08-29T09:37:26.339Z]   identities: "",
[2022-08-29T09:37:26.339Z]   status: "500",
[2022-08-29T09:37:26.339Z]   duration: "46586"
[2022-08-29T09:37:26.339Z] }
[2022-08-29T09:37:26.379Z] Stopping host...
[2022-08-29T09:37:26.403Z] Stopping JobHost
[2022-08-29T09:37:26.421Z] Job host stopped
[2022-08-29T09:37:26.482Z] Host shutdown completed.

There is still an issue with it, as noted in the following line: [2022-08-29T09:37:26.278Z] System.Private.CoreLib: Exception while executing function: Functions.HttpTrigger1. Microsoft.Azure.WebJobs.Script: Did not find any initialized language workers. Its a plain and simple template HTTP Trigger function, nothing fancy: init.py

import logging

import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    return func.HttpResponse(f"Hello. This HTTP triggered function executed successfully.")

Anyone has any idea?

adradr commented 2 years ago

Anyone has any idea?

My bad... had to reload the terminal and it finally started working...

DinnerMonster commented 2 years ago

I am trying to use Azure Event hubs and @lucafrost 's comment fixed the error for my environment. Many thanks from :octocat:

NeverTheSame commented 2 years ago

The workaround didn't work for me. arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" produces:

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R kirill:admin /usr/local/Homebrew
==> Downloading and installing Homebrew...
HEAD is now at 0cf999eee Merge pull request #13775 from Homebrew/brew_deps_args
Updated 1 tap (homebrew/core).
Error: Failed to link all completions, docs and manpages:
  Permission denied @ rb_file_s_symlink - (../../../Homebrew/completions/zsh/_brew, /usr/local/share/zsh/site-functions/_brew)
Failed during: /usr/local/bin/brew update --force --quiet

I did set my terminal to use Rosetta and arch is i386

hjlarrea commented 2 years ago

Hi, due to an internal platform upgrade, the release of Python 3.10 has been delayed to September 31. Support for M1 Macs will also be available upon the release. I will keep this thread posted on any new updates. Thanks a lot for your patience while we get this resolved.

@shreyabatra4 is everything still on track for the end of September? Thanks!

Vasiharan commented 2 years ago

@shreyabatra4 Any update on when we will get a fix please?

rdruzhkov commented 2 years ago

Hi, @shreyabatra4 ! Could you estimate when the Python worker will support M1 Macs?

shreyabatra4 commented 2 years ago

Hi all, due to a delay with a release that support for Python 3.10 is dependent on, this has been delayed to end of October. Thanks a lot for your patience here and apologies for the delay.

aersam commented 2 years ago

Hi all, due to a delay with a release that support for Python 3.10 is dependent on, this has been delayed to end of October. Thanks a lot for your patience here and apologies for the delay.

If you're doing Python 3.10.... how about 3.11, too :) ?