Skip to content

DllNotFoundException:Could not load python311.dll #2502

@roywang91

Description

@roywang91

Environment

  • Pythonnet version: 3.03
  • Python version: 3.11
  • Operating System: Windows
  • .NET Runtime:net8.0

Details

  • Describe what you were trying to get done.

    I am using pythonnet to write a C# project, but I encountered a problem with the Chinese path.When
    PythonEngine.Initialize(),Rethrow as DllNotFoundException: Could not load D:/Test中文/v2647_Debug/StreamingAssets/python-3.11.3-
    embed-amd64/python311.dll.If it is a non-Chinese path, everything works fine.

  • What commands did you run to trigger this issue? If you can provide a

  var pythonHome= $"{Application.streamingAssetsPath}/{PythonFolder}";
  var pythonPath = string.Join(";",
      $"{pythonHome}/Lib/site-packages",
      $"{pythonHome}/{PythonZip}",
      $"{pythonHome}"
  );
  var scripts = $"{pythonHome}/Scripts";
  var path = Environment.GetEnvironmentVariable("PATH")?.TrimEnd(';');
  path = string.IsNullOrEmpty(path) ? $"{pythonHome};{scripts}" : $"{pythonHome};{scripts};{path}";
  Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process);
  Environment.SetEnvironmentVariable("DYLD_LIBRARY_PATH", $"{pythonHome}/Lib", EnvironmentVariableTarget.Process);
  Environment.SetEnvironmentVariable("PYTHONNET_PYDLL", $"{pythonHome}/{PythonDll}", EnvironmentVariableTarget.Process);
  PythonEngine.PythonHome = pythonHome;
  PythonEngine.PythonPath = pythonPath;
  Runtime.PythonDLL =  $"{pythonHome}/{PythonDll}";
  PythonEngine.Initialize();
  • If there was a crash, please include the traceback here.
Win32Exception: 找不到指定的模块Rethrow as DllNotFoundException: Could not load D:/USD_中文/USD_中文/UnityApp/FactoryStream_Data/StreamingAssets/python-3.11.3-embed-amd64/python311.dll.
  at Python.Runtime.Platform.WindowsLoader.Load (System.String dllToLoad) [0x00037] in <e6978fb1f69f4558807e0a3431702c70>:0 
  at Python.Runtime.Runtime+Delegates.GetUnmanagedDll (System.String libraryName) [0x00009] in <e6978fb1f69f4558807e0a3431702c70>:0 
  at Python.Runtime.Runtime+Delegates..cctor () [0x0000a] in <e6978fb1f69f4558807e0a3431702c70>:0 
Rethrow as TypeInitializationException: The type initializer for 'Delegates' threw an exception.
  at Python.Runtime.Runtime.PyGILState_Ensure () [0x00000] in <e6978fb1f69f4558807e0a3431702c70>:0 
  at Python.Runtime.PythonEngine.AcquireLock () [0x00000] in <e6978fb1f69f4558807e0a3431702c70>:0 
  at Python.Runtime.Py+GILState..ctor () [0x00006] in <e6978fb1f69f4558807e0a3431702c70>:0 
  at Python.Runtime.Py.GIL () [0x00007] in <e6978fb1f69f4558807e0a3431702c70>:0 
  at FSM.USD.UsdEngine.Init () [0x00000] in <409251060049431d992f8d5358cc24fc>:0 
  at FSM.USD.UsdEngine..ctor () [0x00006] in <409251060049431d992f8d5358cc24fc>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in <321eb2db7c6d43ea8fc39b54eaca3452>:0 
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
  at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x0001a] in <321eb2db7c6d43ea8fc39b54eaca3452>:0 
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic, System.Boolean wrapExceptions) [0x00095] in <321eb2db7c6d43ea8fc39b54eaca3452>:0 
  at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean wrapExceptions, System.Boolean skipCheckThis, System.Boolean fillCache) [0x00009] in <321eb2db7c6d43ea8fc39b54eaca3452>:0 
  at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Boolean wrapExceptions, System.Threading.StackCrawlMark& stackMark) [0x00027] in <321eb2db7c6d43ea8fc39b54eaca3452>:0 
  at System.Activator.CreateInstance[T] () [0x00015] in <321eb2db7c6d43ea8fc39b54eaca3452>:0 
  at Singleton`1[T]..cctor () [0x00000] in <409251060049431d992f8d5358cc24fc>:0 
Rethrow as TypeInitializationException: The type initializer for 'Singleton`1' threw an exception.
  at ProtocolMgrWPF.ImportModelFromCloudLibraryByWpf (SharedMemoryLib.IMsg msg) [0x00197] in <409251060049431d992f8d5358cc24fc>:0 
  at ProtocolMgrWPF.ImportResourceByPathByWPF (SharedMemoryLib.IMsg message) [0x00052] in <409251060049431d992f8d5358cc24fc>:0 
  at NetManager.MessageUpdate () [0x000ba] in <409251060049431d992f8d5358cc24fc>:0 
  at NetManager.FixedUpdate () [0x00000] in <409251060049431d992f8d5358cc24fc>:0 

Greetings!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions