1

I am having a weird error trying to use .NET dll in a python program.

C:\temp>"c:\apps\WPy64-37120\pypy3.7-v7.3.7-win64\python.exe" example.py

Failed to initialize pythonnet: System.TypeInitializationException: The type initializer for 'Delegates' threw an exception. ---> Python.Runtime.BadPythonDllException: Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL. See https://github.com/pythonnet/pythonnet#embedding-python-in-net ---> System.MissingMethodException: Failed to load symbol Py_IncRef. ---> System.ComponentModel.Win32Exception: The specified procedure could not be found

--- End of inner exception stack trace --- at Python.Runtime.Platform.WindowsLoader.GetFunction(IntPtr hModule, String procedureName) at Python.Runtime.Runtime.Delegates.GetFunctionByName(String functionName, IntPtr libraryHandle) --- End of inner exception stack trace --- at Python.Runtime.Runtime.Delegates.GetFunctionByName(String functionName, IntPtr libraryHandle) at Python.Runtime.Runtime.Delegates..cctor() --- End of inner exception stack trace --- at Python.Runtime.Runtime.Delegates.get_PyGILState_Ensure() at Python.Runtime.Runtime.PyGILState_Ensure() at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size) at Python.Runtime.Runtime.Delegates.get_PyGILState_Ensure() at Python.Runtime.Runtime.PyGILState_Ensure() at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)Traceback (most recent call last): File "example.py", line 2, in from SimpleAxisFile import SimpleAxisFile File "c:\apps\WPy64-37120\pypy3.7-v7.3.7-win64\site-packages\SimpleAxisFile_init_.py", line 16, in import clr File "c:\apps\WPy64-37120\pypy3.7-v7.3.7-win64\site-packages\clr.py", line 6, in load() File "c:\apps\WPy64-37120\pypy3.7-v7.3.7-win64\site-packages\pythonnet_init_.py", line 44, in load raise RuntimeError("Failed to initialize Python.Runtime.dll") RuntimeError: Failed to initialize Python.Runtime.dll

The same code used to work with WinPython 3.7 before.

I do have PYTHONNET_PYDLL environment variable set to "C:\apps\WPy64-37120\pypy3.7-v7.3.7-win64\site-packages\pythonnet\runtime\Python.Runtime.dll"

Any ideas why it is not working?

Thank you.

1 Answer 1

1
  1. We (Python.NET) do no support PyPy. I believe it does not provide the same C API as CPython, so it is expected not to work.
  2. PYTHONNET_PYDLL must point to the DLL that comes with Python, not to Python.Runtime.dll. On Windows for CPython 3.9 (for example) it would be called python39.dll and should be at the root of the Python installation directory.
  3. If you installed pythonnet from PyPi and your entry point is Python and not .NET, you should not need to set PYTHONNET_PYDLL. The only reason you see it in the error message is because you are trying to use PyPy.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.