【发布时间】:2013-01-25 11:28:25
【问题描述】:
我正在尝试使用 clr 模块中的 AddReference('example_file') 方法添加对“example_file.dll”的引用:
>>>import clr
>>>clr.AddReference('example_file')
结果我得到:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
System.IO.FileNotFoundException: Unable to find assembly 'example_file'.
at Python.Runtime.CLRModule.AddReference(String name)
所有文件都位于当前工作目录中,sys.path 如下所示:
>>> sys.path
['', 'C:\\Python27\\lib\\site-packages\\pip-1.2.1-py2.7.egg', 'C:\\Python27', 'C
:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27\\lib\\
site-packages', 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\']
另外,结果是:
>>>clr.FindAssembly('example_file')
我明白了
u'example_file.dll
问题每天都出现。我很困惑,因为它以前工作得很好——我不知道会对此产生什么影响。 我正在使用 Windows 7 x64、python 2.73 和 .Net 框架 4
【问题讨论】:
-
您是否尝试过使用
clr.AddReferenceToFileAndPath来明确表达? -
example_file.dll是针对 .NET 4 编译的吗?见stackoverflow.com/questions/13259617/… 和sourceforge.net/p/pythonnet/bugs/18 与“之前”相比有什么变化吗? -
每个人都可能会同意并强烈建议您摆脱已有十年历史且过时的 Python2.7,并实现 Py3.7+ 的巨大飞跃。
-
AttributeError: 模块 'clr' 没有属性 'AddReference'
标签: python .net python-2.7 ironpython