-1

On Win10 1709 x64 PC, installed Python 3.7.4 64-bit and pythonnet-2.4.0-cp37-cp37m-win_amd64.whl. Confirmed clr.pyd and Python.Runtime.dll exist in:

C:\Users\me\AppData\Local\Programs\Python\Python37\Lib\site-packages\

Placed My.Assembly.dll in:

C:\Users\me\AppData\Local\Programs\Python\Python37\DLLs\

This script fails:

import clr
clr.AddReference("My.Assembly")

with error:

AttributeError: module 'clr' has no attribute 'AddReference'

When I remove the 2nd line, import clr succeeds, so it is finding clr.pyd.

Here are my currently-installed packages:

astroid==2.0.4
bottle==0.12.13
certifi==2018.10.15
chardet==3.0.4
colorama==0.3.9
conan==1.9.1
deprecation==2.0.6
distro==1.1.0
fasteners==0.14.1
future==0.16.0
idna==2.7
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
monotonic==1.5
node-semver==0.2.0
packaging==18.0
patch==1.16
pluginbase==0.7
Pygments==2.2.0
PyJWT==1.6.4
pylint==2.1.1
pyparsing==2.3.0
pythonnet==2.4.0
PyYAML==3.13
requests==2.20.1
six==1.11.0
tqdm==4.28.1
urllib3==1.24.1
wrapt==1.10.11

Jim C
  • 4,517
  • 7
  • 29
  • 33

2 Answers2

2

There is possibly a naming conflict with the clr string styling package, which imports from Lib\site-packages\clr\style_builder.py and contains no AddReference() method.

The correct clr module source code via the pythonnet package looks like this.

Try pip install pythonnet in a fresh environment to be sure there is no package conflict, then retry:

import clr
clr.AddReference()

kung-fu-kenny
  • 81
  • 1
  • 5
  • Welcome to SO and thanks for the reply. I didn't have that package installed. I updated my post to include the ones I do have. – Jim C Jul 16 '19 at 14:56
1

I had a script named clr.py in my scripts folder :( Deleted it and all is good now.

Jim C
  • 4,517
  • 7
  • 29
  • 33