Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Azure AppService and System.DllNotFoundException: Could not load python311.dll with flags RTLD_NOW | RTLD_GLOBAL: python311.dll: cannot open shared object file: No such file or directory #120

Open
dariusz-wozniak opened this issue Apr 3, 2023 · 5 comments

Comments

@dariusz-wozniak
Copy link

dariusz-wozniak commented Apr 3, 2023

Hi, I'm using Numpy 3.11.1.33 and:

When running the project locally, the project along with Numpy-related code works fine.

But, after deployment to the Azure AppService, website stopped working with error:

Unhandled exception. System.TypeInitializationException: The type initializer for 'Delegates' threw an exception.
---> System.DllNotFoundException: Could not load python311.dll with flags RTLD_NOW | RTLD_GLOBAL: python311.dll: cannot open shared object file: No such file or directory
at Python.Runtime.Platform.PosixLoader.Load(String dllToLoad)
at Python.Runtime.Runtime.Delegates.GetUnmanagedDll(String libraryName)
at Python.Runtime.Runtime.Delegates..cctor()
--- End of inner exception stack trace ---
at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv, Boolean initSigs)
at Python.Runtime.PythonEngine.Initialize()
at Numpy.np.InstallAndImport(Boolean force)
at Numpy.np.<>c.b__531_0()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Numpy.np.get_self()
at Numpy.np.arange(Int32 stop, Int32 step, Dtype dtype)
// ..

I'm using initialization of Python in the Program.cs before CreateHostBuilder(args).Build();:

np.arange(1);
Python.Runtime.PythonEngine.BeginAllowThreads();

Any ideas what's wrong? Is that because of installation fails? If yes, is it possible to use portable Python that is placed under application after build?

Note that targeted machine is a Linux, but the project is used locally in Windows/Linux/Mac environments.

@henon
Copy link
Contributor

henon commented Apr 3, 2023

Probably the installation fails because the default install directory is in the user directory.

@dariusz-wozniak
Copy link
Author

When I run:

import sys; print(sys.path)

I get:

['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/dist-packages', '/usr/lib/python3/dist-packages']

How can I point to the proper directory?

@henon
Copy link
Contributor

henon commented Apr 3, 2023

I'll look later when I got time as I am quite busy but you can check out Python.Included which is used by numpy.net under the hood and see if you find out yourself.

@ddombrowsky
Copy link

Can we assume that Numpy.NET using Python.Included is a windows-only package (and thus not suitable for azure linux-based containers)?

@henon
Copy link
Contributor

henon commented Jul 8, 2023

Yes Python.Included and Numpy.NET are Windows only libs because they contain the windows version of python and numpy, but they each have a companion library that can be used with linux. You have to pack a linux version of python and the numpy wheel in your .NET assembly (as embedded resources) and then use Python.Deployment to install them. See the examples in the https://github.com/henon/Python.Included repo. Then you can use Numpy.Bare to use the numpy wheel you installed.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants