首页 > 解决方案 > Sagemaker 上的 pythonnet 无法导入 clr

问题描述

出现此错误,我无法从 SageMaker 导入 clr。什么样的调整使这个成功?

从 Sagemaker 控制台:

source activate python3    
conda install pythonnet

这似乎可以很好地安装 pythonnet 而不会出错。

在python代码中:

import clr

这会产生此错误:

Traceback (most recent call last):
  File "test_clr.py", line 1, in <module>
    import clr
ImportError: System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: /home/ec2-user/anaconda3/envs/python3/lib/../lib/libmono-native.so assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
  at Interop+Sys..cctor () [0x00000] in <aa5dff9b31c64fce86559bbbf6cd364f>:0 
   --- End of inner exception stack trace ---
  at Interop.GetRandomBytes (System.Byte* buffer, System.Int32 length) [0x00000] in <aa5dff9b31c64fce86559bbbf6cd364f>:0 
  at System.Guid.FastNewGuidArray () [0x00020] in <aa5dff9b31c64fce86559bbbf6cd364f>:0 
  at System.Reflection.Emit.ModuleBuilder..ctor (System.Reflection.Emit.AssemblyBuilder assb, System.String name, System.String fullyqname, System.Boolean emitSymbolInfo, System.Boolean transient) [0x00035] in <aa5dff9b31c64fce86559bbbf6cd364f>:0 
  at System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule (System.String name, System.String fileName, System.Boolean emitSymbolInfo, System.Boolean transient) [0x0005b] in <aa5dff9b31c64fce86559bbbf6cd364f>:0 
  at System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule (System.String name) [0x00000] in <aa5dff9b31c64fce86559bbbf6cd364f>:0 
  at Python.Runtime.CodeGenerator..ctor () [0x0002b] in <0e10ac2b10a44c1baa160aa337220b6a>:0 
  at Python.Runtime.DelegateManager..ctor () [0x00061] in <0e10ac2b10a44c1baa160aa337220b6a>:0 
  at Python.Runtime.PythonEngine.Initialize (System.Collections.Generic.IEnumerable`1[T] args, System.Boolean setSysArgv, System.Boolean initSigs) [0x0000a] in <0e10ac2b10a44c1baa160aa337220b6a>:0 
  at Python.Runtime.PythonEngine.Initialize (System.Boolean setSysArgv, System.Boolean initSigs) [0x00005] in <0e10ac2b10a44c1baa160aa337220b6a>:0 
  at Python.Runtime.PythonEngine.InitExt () [0x00000] in <0e10ac2b10a44c1baa160aa337220b6a>:0 

环境 :

类似症状:

尝试导入 clr 时出现 System.DllNotFoundException,尽管引用的程序集存在 #1034:我在正确的目录中确认了 libmono-native.so 库。

标签: monoamazon-sagemakerpython.net

解决方案


推荐阅读