clr.AddReference('example_file') - 无法找到程序集

use*_*461 5 .net python ironpython python-2.7

我正在尝试使用 clr 模块中的 AddReference('example_file') 方法添加对“example_file.dll”的引用:

>>>import clr
>>>clr.AddReference('example_file')
Run Code Online (Sandbox Code Playgroud)

结果我得到:

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)
Run Code Online (Sandbox Code Playgroud)

所有文件都位于当前工作目录中,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\\']
Run Code Online (Sandbox Code Playgroud)

此外,由于:

>>>clr.FindAssembly('example_file')
Run Code Online (Sandbox Code Playgroud)

我明白了

u'example_file.dll 
Run Code Online (Sandbox Code Playgroud)

问题一天天出现。我很困惑,因为它以前工作得很好 - 我不知道什么会对此产生影响。我正在使用 Windows 7 x64、python 2.73 和 .Net Framework 4

not*_*bit 0

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

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