从pythonjupyter笔记本运行c#函数

问题描述

我有这个文件chello.cs

using System;

namespace HelloWorldApp {
 
    class Geeks {
  
        static void Main(string[] args) { 
              
            // statement 
            // printing Hello World! 
            Console.WriteLine("Hello World!"); 
              
            // To prevents the screen from  
            // running and closing quickly 
            Console.ReadKey(); 
        } 
    } 
} 

我想从jupyter笔记本中的python调用它。 我正在使用pythonnet并尝试类似的方法

import clr

clr.AddReference(r'chello')

from HelloWorldApp import Geeks

my = Geeks()

my.Main()

但是它不起作用,它显示错误

FileNotFoundException: Unable to find assembly 'chello'.
   at Python.Runtime.CLRModule.AddReference(String name)

解决方法

Zeroth,为了澄清一下,您实际上在编译C#吗?

首先,考虑到其中包含Main,程序集名称可能是chello.exe。

第二,根据文件系统的布局,您需要将目录添加到PATH环境变量中,或将完整路径传递到AddReference