Python: Attributeerror: 'Module' Object Has No Attribute '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:

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.

3 Answers

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.

2

You must be using the wrong 'clr' module. remove it

pip uninstall clr

And then install 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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.