简体   繁体   English

Python:AttributeError:'module'对象没有属性'AddReference'?

[英]Python: AttributeError: 'module' object has no attribute 'AddReference'?

Am trying to use clr.AddReference and clr.AddReferenceToFile to import an assembly, but python(2.7) keeps making this error:我正在尝试使用 clr.AddReference 和 clr.AddReferenceToFile 来导入程序集,但 python(2.7) 不断出现此错误:

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    clr.AddReference("UnityEngine")
AttributeError: 'module' object has no attribute 'AddReference'

Can anyone tell me how to fix this.谁能告诉我如何解决这个问题。

Once I met this issue.一旦我遇到这个问题。 There is a package named clr while the pythonnet package's alias is also clr .有一个名为clr的包,而pythonnet包的别名也是clr So I removed clr by " pip uninstall clr " and then installed pythonnet by ' pip install pythonnet '.所以我删除了由“CLR pip uninstall clr ”,然后安装了pythonnet“ pip install pythonnet ”。 Finally, everything works well.最后,一切正常。

You must be using the wrong 'clr' module.您一定使用了错误的“clr”模块。 remove it去掉它

pip uninstall clr

And then install pythonnet然后安装pythonnet

pip install pythonnet

run the code运行代码

import clr
dir(clr)

if the reasult is as ['StyleBuilder', ' builtins ', ' cached ',....] then the problem is your IDE is installing the WRONG Clr module如果reasult是[“StyleBuilder”,“建宏”,“缓存”,...]那么问题就是你的IDE是安装了错误的CLR模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:&#39;module&#39;对象没有属性&#39;subscribe&#39;Python - AttributeError: 'module' object has no attribute 'subscribe' Python AttributeError:&#39;module&#39;对象没有属性&#39;call&#39;:Python - AttributeError:'module' object has no attribute 'call' :Python Python-&gt; AttributeError:“模块”对象没有属性“主” - Python -> AttributeError: 'module' object has no attribute 'main' python AttributeError:“模块”对象没有属性“ monthcalendar” - python AttributeError: 'module' object has no attribute 'monthcalendar' python 属性错误:“模块”object 没有属性“fft” - python attributeerror: 'module' object has no attribute 'fft' Python AttributeError:“模块”对象没有“连接”属性 - Python AttributeError: 'module' object has no attribute 'connect' AttributeError:“模块”对象在python中没有属性“ windll” - AttributeError: 'module' object has no attribute 'windll' in python Python 2:AttributeError:“模块”对象没有属性“扫描” - Python 2: AttributeError: 'module' object has no attribute 'scan' Python:AttributeError:“模块”对象没有属性 - Python: AttributeError: 'module' object has no attribute Python:AttributeError:“模块”对象没有属性“附加” - Python: AttributeError: 'module' object has no attribute 'append'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM