Azure / azure-uamqp-python

AMQP 1.0 client library for Python
MIT License
56 stars 48 forks source link

Symbol not found: _SASToken_CreateString on Apple Silicon with Azure Functions #278

Open jimbobbennett opened 2 years ago

jimbobbennett commented 2 years ago

Describe the bug When importing the azure.iot.hub package into an Azure Functions Project, the application throws an ImportError:

Result: Failure
[2021-09-30T19:48:47.531Z] Exception: ImportError: dlopen(/Users/jim/scratch-pad/.venv/lib/python3.9/site-packages/uamqp/c_uamqp.cpython-39-darwin.so, 2): Symbol not found: _SASToken_CreateString
[2021-09-30T19:48:47.531Z]   Referenced from: /Users/jim/scratch-pad/.venv/lib/python3.9/site-packages/uamqp/c_uamqp.cpython-39-darwin.so
[2021-09-30T19:48:47.531Z]   Expected in: flat namespace
[2021-09-30T19:48:47.531Z]  in /Users/jim/scratch-pad/.venv/lib/python3.9/site-packages/uamqp/c_uamqp.cpython-39-darwin.so. Troubleshooting Guide: https://aka.ms/functions-modulenotfound
[2021-09-30T19:48:47.531Z] Stack:   File "/opt/homebrew/Cellar/azure-functions-core-tools@3/3.0.3734/workers/python/3.9/OSX/X64/azure_functions_worker/dispatcher.py", line 305, in _handle__function_load_request
[2021-09-30T19:48:47.531Z]     func = loader.load_function(
[2021-09-30T19:48:47.531Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@3/3.0.3734/workers/python/3.9/OSX/X64/azure_functions_worker/utils/wrappers.py", line 42, in call
[2021-09-30T19:48:47.531Z]     raise extend_exception_message(e, message)
[2021-09-30T19:48:47.531Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@3/3.0.3734/workers/python/3.9/OSX/X64/azure_functions_worker/utils/wrappers.py", line 40, in call
[2021-09-30T19:48:47.531Z]     return func(*args, **kwargs)
[2021-09-30T19:48:47.531Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@3/3.0.3734/workers/python/3.9/OSX/X64/azure_functions_worker/loader.py", line 83, in load_function
[2021-09-30T19:48:47.531Z]     mod = importlib.import_module(fullmodname)
[2021-09-30T19:48:47.532Z]   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
[2021-09-30T19:48:47.532Z]     return _bootstrap._gcd_import(name[level:], package, level)
[2021-09-30T19:48:47.532Z]   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
[2021-09-30T19:48:47.532Z]   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
[2021-09-30T19:48:47.532Z]   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
[2021-09-30T19:48:47.532Z]   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
[2021-09-30T19:48:47.532Z]   File "<frozen importlib._bootstrap_external>", line 850, in exec_module
[2021-09-30T19:48:47.532Z]   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
[2021-09-30T19:48:47.532Z]   File "/Users/jim/scratch-pad/iot-trigger/__init__.py", line 6, in <module>
[2021-09-30T19:48:47.532Z]     from azure.iot.hub import IoTHubRegistryManager
[2021-09-30T19:48:47.532Z]   File "/Users/jim/scratch-pad/.venv/lib/python3.9/site-packages/azure/iot/hub/__init__.py", line 6, in <module>
[2021-09-30T19:48:47.532Z]     from .iothub_registry_manager import IoTHubRegistryManager
[2021-09-30T19:48:47.532Z]   File "/Users/jim/scratch-pad/.venv/lib/python3.9/site-packages/azure/iot/hub/iothub_registry_manager.py", line 6, in <module>
[2021-09-30T19:48:47.532Z]     from . import iothub_amqp_client
[2021-09-30T19:48:47.532Z]   File "/Users/jim/scratch-pad/.venv/lib/python3.9/site-packages/azure/iot/hub/iothub_amqp_client.py", line 23, in <module>
[2021-09-30T19:48:47.532Z]     import uamqp
[2021-09-30T19:48:47.532Z]   File "/Users/jim/scratch-pad/.venv/lib/python3.9/site-packages/uamqp/__init__.py", line 12, in <module>
[2021-09-30T19:48:47.532Z]     from uamqp import c_uamqp  # pylint: disable=import-self

To Reproduce Steps to reproduce the behavior:

  1. Create an Azure Functions project
  2. Add azure-iot-hub to the requirements.txt file, create a virtual environment and install the packages from this file
  3. Import from azure.iot.hub in the __init__.py file

You can find a project to reproduce this here: https://github.com/jimbobbennett/iot-func-error

Expected behavior It should work and not thrown an exception.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

yunhaoling commented 2 years ago

hey @jimbobbennett , apologize for the late response and thanks for the link to your repo.

the uamqp doesn't provide apple M1 yet (arm-based) wheel yet, we only support wheels for x86 & x86-64, which means on Apple M1, the library uamqp-python (based on uamqp-c) will need to build itself first which requires extra dependencies.

Are you working with the Apple M1 for local development? one workaround you could try locally is to put cython into the requirements.txt of the Azure Function to see if it helps the compilation of the library on your Apple M1.

jimbobbennett commented 2 years ago

@yunhaoling - tried that, same error.

SiddyP commented 2 years ago

Hi @jimbobbennett perhaps this could work? I develop azure functions locally and to get around import issues with uamqp I create the venv and install the dependencies using Rosetta. I haven't tried it with azure-iot-hub though.

trevors20 commented 2 years ago

@yunhaoling, thanks for the info. Would you know of a timeline when uamqp would support Apple M1?

GuMiner commented 2 years ago

I was running into this problem even when building directly from the source. I had to add the following line in setup.py on line 172 when cmakeing azure-uamqp-c, so that azure-uamqp-c would be built universal.

""-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64"",

tonyjune commented 1 year ago

I am facing the same issue. Anything we can do as a temporary fix?

jooskesters commented 1 year ago

pip uninstall uamqp pip install uamqp --no-binary uamqp

found the solution here: https://apple.stackexchange.com/questions/436801/m1-mac-mach-o-file-but-is-an-incompatible-architecture-have-x86-64-need-a