我正在起诉CPython 2.7,并为.NET clr软件包安装了Python。我不想使用Iron Python。
当我从MING32命令行运行python时,它可以工作:
PC@User /c/Users
$ python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReference(r"C:\Users\MasterEmulator")
<System.Reflection.RuntimeAssembly object at 0x02368F30>
无论如何我从python脚本执行相同的代码都失败了:
PC@User /c/Users
$ cat s.py
import clr
clr.AddReference(r"C:\Users\MasterEmulator")
PC@User /c/Users
$ python s.py
Traceback (most recent call last):
File "s.py", line 2, in <module>
clr.AddReference(r"C:\Users\MasterEmulator")
System.IO.FileNotFoundException: Unable to find assembly 'C:\Users\MasterEmulator'.
at Python.Runtime.CLRModule.AddReference(String name)
我在这里做错了什么?
编辑:此脚本有效。似乎绝对路径的问题......
import clr
clr.AddReference(r"../Users/MasterEmulator")
答案 0 :(得分:1)
How to use a C# dll in IronPython
sys.path.append(r&#34; C:\ Folder \ Subfolder&#34;)dll的路径
clr.AddReference(&#34; Ipytest.dll&#34;)#dll