Search code examples
pythonazureimportimporterrorswig

swig compiled binary Python Azure import error


I'm trying to run an azure function app. I've created the file structure, functions, etc. as needed for my code to run. When I run locally, everything works just fine. However, when I deploy to the Azure function app and try to run on the server, I get an import error: ImportError: cannot import name '_<swig_compiled_binary>' from 'other_functions_path'

I can't understand why this would be the case. For those wondering, the package structure is as follows:

HttpTriggerIntro
  __init__.py
  function.json
other_functions_path
  __init__.py
  other_functions.py
  _<swig_compiled_binary>.pyd

I don't have any external library imports beyond the swig compiled binary file, everything else is standard python 3.7 library calls, and as I said, everything works locally in the virtual environment.

If more info is needed I can provide it.

Edit: removed portion where I talked about circular import, this is not the cause.


Solution

  • Figured it out. Azure functions use a linux operating system for python runtime stacks. If you use a .pyd, that is compiled on windows, and the azure runtime stack will not recognize it. You have to use a .so compiled on linux for this to work.