我试图让pythonnet在运行在Linux上的.Net核心应用程序中工作。
我在我的Python.Runtime.dll核心项目中引用了努基特(这是从努基特获得的)。
我的代码是:
using System;
using Python.Runtime;
namespace pythonnet_w
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start");
using (**Py.GIL()**) {
// blabla
}
Console.WriteLine("End");
}
}
}我得到这个运行时错误:
Unhandled Exception: System.MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder
System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
at Python.Runtime.CodeGenerator..ctor()
at Python.Runtime.DelegateManager..ctor()
at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv)
at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv)
at Python.Runtime.PythonEngine.Initialize()
at Python.Runtime.Py.GIL()
at pythonnet_w.Program.Main(String[] args) in D:\Development\~.Net libraries (3.part)\phytonnet\.Net Core test (phytonnet)\c#\pythonnet_test\Program.cs:line 10
/usr/sbin/pythonnet_w: line 5: 19487 Aborted dotnet "/usr/share/pythonnet_wit/pythonnet_w.dll"试图在这些线程中找到解决方案,但没有任何结果:
更新:
我试图在Visual中打开\pythonnet-master\src\runtime**Python.Runtime.csproj**,看看是否可以将其编译为.Net或.Core,但只能编译到.Net框架。我发现这篇文章"如何从.net框架移植到.net标准“是我必须做的吗?
发布于 2019-05-10 22:58:30
通过使用2.4.0版本的自编译Python.Runtime.dll,我终于取得了成功。创建工作DLL有两个选项:
net461 (只保留netstandard2.0)。dotnet build对于选项2,下面的工作(在Windows和Linux中):
cd src\runtimedotnet build -c ReleaseWinPY3 -f netstandard2.0 Python.Runtime.15.csproj (在Mac/Linux中,用ReleaseMonoPY3替换ReleaseWinPY3,因为前者使用python37,后者使用python3.7)DYLD_LIBRARY_PATH或LD_LIBRARY_PATH (Windows):export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.7/libnetcoreapp2.2,netcoreapp3.1也测试好),例如结合以下代码,using System;
using Python.Runtime;
namespace Python_CSharp
{
class Program
{
static void Main(string[] args)
{
using (Py.GIL())
{
dynamic os = Py.Import("os");
dynamic dir = os.listdir();
Console.WriteLine(dir);
foreach (var d in dir)
{
Console.WriteLine(d);
}
}
}
}
}发布于 2020-06-14 22:52:15
您可以在您的IronPython应用程序中托管.NET解释器。例如,使用NuGet,您可以下载正确的包,然后将脚本执行(实际上是IronPython引擎)嵌入到应用程序中。
https://stackoverflow.com/questions/53628176
复制相似问题