Python: AttributeError: 'module' object has no attribute 'AddReference'?

Ran picture Ran · Dec 20, 2017 · Viewed 13.3k times · Source

Am trying to use clr.AddReference and clr.AddReferenceToFile to import an assembly, but python(2.7) keeps making this error:

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.

Answer

Guancheng Li picture Guancheng Li · Apr 3, 2018

Once I met this issue. There is a package named clr while the pythonnet package's alias is also clr. So I removed clr by "pip uninstall clr" and then installed pythonnet by 'pip install pythonnet'. Finally, everything works well.