【问题标题】:clr.AddReference('example_file') - unable to find assemblyclr.AddReference('example_file') - 无法找到程序集
【发布时间】: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


【解决方案1】:

这里的信息还不够,但有(至少)两件事需要考虑:

  1. 您没有设置额外的 Python 相关环境变量。例如使用虚拟环境或让 Python 指向其他地方。 Please check 如果设置了 PYTHONHOMEPYTHONPATH
  2. 您尝试加载的 DLL 具有与 Python 解释器相同的位大小。 IE 。如果您有 64 位 Python,则可能需要(但不总是)加载 64 位 DLL。
  3. 在您的字符集中正确读取了路径规范。
    sys.path.append(r"C:\Program Files\SomeApi")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-10
    • 2011-05-03
    • 1970-01-01
    • 2011-07-07
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多