pythonnet / pythonnet/clr-loader

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

Offen
#74 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
42
Forks
32
Ø Merge
14 Std. 1 Min.
Gemergte PRs (30 T.)
1

Beschreibung

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>

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, import clr in der virtuellen Umgebung auf dem M-Laufwerk zu reproduzieren und mit der funktionierenden Umgebung auf dem W-Laufwerk zu vergleichen. Untersuche lib\site-packages\clr_loader\netfx.py, insbesondere pyclr_get_function, sowie den gemeldeten Pfad zu Python.Runtime.dll. Als erledigt gilt, den Grund zu identifizieren, warum Python.Runtime.Loader.Initialize lokal aufgelöst wird, aber auf dem Netzlaufwerk NULL zurückgibt, mit einer reproduzierbaren Behebung oder einer klaren Einschränkung.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.