'System.IO.FileNotFoundException: Unable to find assembly' 在 Python 的 clr 库中

'System.IO.FileNotFoundException: Unable to find assembly' in clr library on Python

我在 .dll 文件中使用的代码中出现汇编错误。这是一个 template code from another thread,很多人声称它有效。

import clr
import os
file = 'CPUThermometerLib.dll'
print('Does this filepath exist?',os.path.isfile(file)) 
clr.AddReference(file)

我猜文件路径没有问题,因为它 return 在 .isfile 函数上是正确的。这是我得到的输出:

Does this filepath exist? True
  File "<stdin>", line 1, in <module>
System.IO.FileNotFoundException: Unable to find assembly 'CPUThermometerLib.dll'.
   at Python.Runtime.CLRModule.AddReference(String name)

我检查了多个线程,其中 none 个线程给出了解决方案。我使用的是Windows 10,而且我的.NET Framework 版本是'4.0.30319.42000'。我的笔记本电脑处理器是 Atom Z3537F。

默认情况下 Windows python 安装中未安装 clr 模块。您需要 运行 pip install clr 在提示符下添加它,然后您的代码才能正确导入它。