美文网首页
python中调用 C#动态链接库问题记录

python中调用 C#动态链接库问题记录

作者: 付壹壹 | 来源:发表于2018-09-07 21:49 被阅读0次

程序[摘自https://blog.csdn.net/LTG01/article/details/80700513] 
import clr
clr.FindAssembly("PythonNetTest.dll") ## 加载c#dll文件
from PythonNetTest import * # 导入命名空间
instance = Class1() #class1是dll里面的类
print(instance.AddShort(2, 3))#一个简单的加法
instance.ShowForm()

【1】报错: AttributeError: 'module' object has no attribute 'FindAssembly'
错误原因:
python存在 clr 模块,python的pythonnet模块中,也存在clr,在import 过程中,
要用的是后者中的clr,因此要利用 pip uninstall clr
把clr模块卸载掉,再运行上面的程序就可以了。
【2】 报错: name "PythonNetTest" has not found
错误原因:
未将PythonNetTest.dll与.py程序,放在同一个目录下,放在同一个目录下即可。

相关文章

网友评论

      本文标题:python中调用 C#动态链接库问题记录

      本文链接:https://www.haomeiwen.com/subject/wnehgftx.html