Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PythonNet FileNotFoundException: Unable to find assembly

I am trying to execute a Python script that uses Python For .Net (https://github.com/pythonnet/pythonnet) to load a C# library called "Kratos_3.dll" which is in the same folder as the script but the file cannot be found.

I have installed clr using "pip install pythonnet".

This is my script:

import clr
import sys
sys.path.insert(0,"C:\\dev\\proj_1\\")
clr.AddReference("Kratos_3") 

I keep getting the error

FileNotFoundException: Unable to find assembly 'Kratos_3. at Python.Runtime.CLRModule.AddReference(String name)

When I run this using IronPython it works, but I would like to get this to work using regular Python 2.7, what do I need to do?

like image 692
baconwichsand Avatar asked Mar 03 '15 20:03

baconwichsand


1 Answers

It turns out that even though I added the path through

sys.path.insert(0,"C:\\dev\\proj_1\\")

it still couldn't find the file because the .dll because Windows was not enabling it to load from "external sources". To fix this:

  1. Right-click on the .dll
  2. "Properties"
  3. Under "General", click "Unblock"
like image 148
baconwichsand Avatar answered Oct 02 '22 17:10

baconwichsand