Search code examples
pythonwindows.net-assembly

'System.IO.FileNotFoundException: Unable to find assembly' in clr library on Python


I am getting an assembly error in my code using in a .dll file. This is a template code from another thread, and a lot of people claimed that it worked.

import clr
import os
file = 'CPUThermometerLib.dll'
print('Does this filepath exist?',os.path.isfile(file)) 
clr.AddReference(file)

There is no problem with the file path I guess since it return true on the .isfile function. Here is the output that I'm getting:

Does this filepath exist? True
  File "<stdin>", line 1, in <module>
System.IO.FileNotFoundException: Unable to find assembly 'CPUThermometerLib.dll'.
   at Python.Runtime.CLRModule.AddReference(String name)

I have checked multiple threads and none of them is giving a solution. I am using Windows 10, and moreover, my .NET framework version is '4.0.30319.42000'. My laptop processor is an Atom Z3537F.


Solution

  • The clr module is not installed by default on the Windows python installation. You will need to run pip install clr at a prompt to have it added and then your code will be able to import it properly.