python-3.xpython.net

Pythonnet missing AddReference method


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


Solution

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