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

问题描述 投票:0回答:1

我正在尝试使用 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 Framework 4

python .net python-2.7 ironpython
1个回答
0
投票

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

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