Skip to content
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

RuntimeError: Failed to resolve Python.Runtime.Loader.Initialize from M:\development\releases\3.9.1\test_venv\lib\site-packages\pythonnet\runtime\Python.Runtime.dll #74

Open
samuelkavuri opened this issue Feb 18, 2025 · 0 comments

Comments

@samuelkavuri
Copy link

I have mapped a network drive (assigned drive letter M) on my local machine, created a virtual environment on it and installed all the supporting libraries that are required to run my application. I get the Python runtime error when I try to import clr directly on virtual environment Python interpreter (located on M drive) console.

M:\development\releases\3.9.1\test_venv\Scripts>python
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import clr
Traceback (most recent call last):
File "", line 1, in
File "M:\development\releases\3.9.1\test_venv\lib\site-packages\clr.py", line 6, in
load()
File "M:\development\releases\3.9.1\test_venv\lib\site-packages\pythonnet_init_.py", line 143, in load
func = assembly.get_function("Python.Runtime.Loader.Initialize")
File "M:\development\releases\3.9.1\test_venv\lib\site-packages\clr_loader\types.py", line 94, in get_function
return ClrFunction(self._runtime, self._path, name, func)
File "M:\development\releases\3.9.1\test_venv\lib\site-packages\clr_loader\types.py", line 58, in init
self._callable = runtime._get_callable(assembly, typename, func_name)
File "M:\development\releases\3.9.1\test_venv\lib\site-packages\clr_loader\netfx.py", line 47, in _get_callable
raise RuntimeError(
RuntimeError: Failed to resolve Python.Runtime.Loader.Initialize from M:\development\releases\3.9.1\test_venv\lib\site-packages\pythonnet\runtime\Python.Runtime.dll

Upon more debugging, I noticed that the lib\site-packages\clr_loader\netfx.py module's pyclr_get_function function returns NULL on the shared drive (M). I'm not sure what exactly is missing on this M drive. But same virtual environment works fine on local drive.

print(f"Assembly Path: {str(Path(assembly_path))}")
print(f"Type Name: {typename}")
print(f"Function Name: {function}")
func = _FW.pyclr_get_function(
self._domain,
str(Path(assembly_path)).encode("utf8"),
typename.encode("utf8"),
function.encode("utf8"),
)
print("Returned Function:", func)

if func == ffi.NULL:
raise RuntimeError(
f"Failed to resolve {typename}.{function} from {assembly_path}"
)

Assembly Path: M:\development\releases\3.9.1\test_venv\lib\site-packages\pythonnet\runtime\Python.Runtime.dll
Type Name: Python.Runtime.Loader
Function Name: Initialize
Output: Returned Function: <cdata 'int(*)(void , int)' NULL>


If I create the same virtual environment on local drive (W:) and try to import clr, it just works fine.

(autobot_venv 3.9.1) W:\Projects\development\test_venv>python
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
**>>>

import clr
**

I see below output `by calling pyclr_get_function function from netfx.py module on local drive
Output: Returned Function: <cdata 'int()(void , int)' 0x0000022653BF407C>

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

1 participant