Skip to content

Encountering dll not found exception using mono #985

New issue

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

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

Already on GitHub? Sign in to your account

Closed
jharonfe opened this issue Nov 9, 2019 · 4 comments
Closed

Encountering dll not found exception using mono #985

jharonfe opened this issue Nov 9, 2019 · 4 comments

Comments

@jharonfe
Copy link

jharonfe commented Nov 9, 2019

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.6.8
  • Operating System: Ubuntu 18.04.3
  • Mono: 6.4.0.198

Details

Attempting to port .NET application from windows to linux running under mono. This application has a dependency on the Python.Runtime.dll version number above.

The build of the program in the code below encounters a DLLNotFoundException.

    public static void Main(string[] args)
        {
            PythonEngine.Initialize();
            using (Py.GIL())
            {
                PythonEngine.Exec("print('hello')");
            }

            Console.WriteLine("done");
            Console.ReadLine();
        }

I've tested variations of the code above that include setting the PYTHONHOME and PATH variables. But I still encounter the same exception.

See the full exception message, stack trace below.

System.DllNotFoundException: python35 assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Python.Runtime.Runtime.Py_IsInitialized()
  at Python.Runtime.Runtime.Initialize () [0x00001] in <11c81f5f20364a28b963bcd102f70399>:0 
  at Python.Runtime.PythonEngine.Initialize (System.Collections.Generic.IEnumerable`1[T] args, System.Boolean setSysArgv) [0x0001b] in <11c81f5f20364a28b963bcd102f70399>:0 
  at Python.Runtime.PythonEngine.Initialize (System.Boolean setSysArgv) [0x00006] in <11c81f5f20364a28b963bcd102f70399>:0 
  at Python.Runtime.PythonEngine.Initialize () [0x00001] in <11c81f5f20364a28b963bcd102f70399>:0 
  at MonoPythonnet.MainClass.Main (System.String[] args) [0x00001] in /home/jon/ws/2019.11.09.test.MonoPythonnet/MonoPythonnet/Program.cs:11 
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: python35 assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Python.Runtime.Runtime.Py_IsInitialized()
  at Python.Runtime.Runtime.Initialize () [0x00001] in <11c81f5f20364a28b963bcd102f70399>:0 
  at Python.Runtime.PythonEngine.Initialize (System.Collections.Generic.IEnumerable`1[T] args, System.Boolean setSysArgv) [0x0001b] in <11c81f5f20364a28b963bcd102f70399>:0 
  at Python.Runtime.PythonEngine.Initialize (System.Boolean setSysArgv) [0x00006] in <11c81f5f20364a28b963bcd102f70399>:0 
  at Python.Runtime.PythonEngine.Initialize () [0x00001] in <11c81f5f20364a28b963bcd102f70399>:0 
  at MonoPythonnet.MainClass.Main (System.String[] args) [0x00001] in /home/jon/ws/2019.11.09.test.MonoPythonnet/MonoPythonnet/Program.cs:11 

I also have included a zip of the output of the mono execution with log level set to debug.
info.log.zip

Some help sorting through this would be greatly appreciated. Thanks.

@lostmsu
Copy link
Member

lostmsu commented Nov 10, 2019

pythonnet packages on NuGet are built for Windows. You need to install Python.NET into you Python with pip (e.g. https://pypi.org/project/pythonnet/), and also have python3.5m.so in your PATH.

@jharonfe
Copy link
Author

Thanks for the feedback. I installed pythonnet 2.4.0. I also added python3.5m.so to the environment path. Unfortunately I still encounter the same DLLNotFoundException for the Python.Runtime.dll at the same spot when running the build of the test program.

The Python.Runtime.dll that's used was sourced from NuGet and you say "are built for Windows". Are there any binaries on NuGet that are compatible with mono ?

I cloned a local copy of the pythonnet.git repo. I see that the solutions there contain build options for mono. I was going to generate a local build of the Python.Runtime project. However when these solution files are opened using monodevelop on ubuntu, the Python.Runtime project does not load with a message "Invalid configuration mapping". Do you have any suggestions how to load this project using monodevelop ?

@lostmsu
Copy link
Member

lostmsu commented Nov 13, 2019

When you install Python.NET from pip, it also installs corresponding version of Python.Runtime.dll somewhere in Python directories, likely site.

@jharonfe
Copy link
Author

jharonfe commented Nov 14, 2019

I tested this last night. Here is a quick summary of what happened:

  1. After I replaced the Python.Runtime.dll with the version from the pythonnet installation I ran the test app again. I no longer encounter the DLLNotFoundException. Unfortunately I encountered a new issue, EntryPointNotFoundException.
  2. I reviewed some of the issues in pythonnet for this exception and there were several that were relevant: Pythonnet crashes .Net application on exit. #245, Using pythonnet in docker container #303, Unable to embed python in C# application on Ubuntu 16.04: System.EntryPointNotFoundException: Py_IsInitialized #740, et al. I tried to implement the solution described in Using pythonnet in docker container #303 but without success, perhaps in part due to the fact that I could not locate some of the artifacts described such as Python.Runtime.dll.config and clr.so.
  3. In the course of reviewing Using pythonnet in docker container #303 I discovered QuantConnect/Lean has a fork of pythonnet. See here. In addition they maintain a set of builds of the forked Python.Runtime project on nuget. See here. I tested the linux version if this dll and was able to get the test program to run under mono.

@jharonfe jharonfe closed this as completed Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants