Reputation: 31
I want to integrate IronPython in my .NET C# Library but I have always the following exception
Additional information: No module named 'modulename'
In my C# library project, I've installed the following IronPython NuGet
Install-Package IronPython
Install-Package IronPython.StdLib
Python simple code (getLogScaledPNG.py):
import numpy as np
import matplotlib.pyplot as plt
def getLogScaledPNG(filename):
data = plt.imread(filename);
data[data == 0.] = np.nan;
logdata = np.log(data);
plt.imsave("logimage.png", logdata, cmap="gray");
print 'Scaled Image Saved'
C# code:
using IronPython.Hosting;
var ipy = Python.CreateRuntime();
dynamic getLogScaledPNG = ipy.UseFile(@".\PythonScripts\getLogScaledPNG.py");
getLogScaledPNG.getLogScaledPNG("toto.png");
When I execute this C# code, I've got the following Exception:
Additional information: No module named numpy
I don't understand where and how can I add this module ? I just have the reference to the IronPython DLLs in my .NET project and I haven't got any folders where I can add this module
Upvotes: 3
Views: 760
Reputation: 323
In addition to the IronPython DLLs, you need Python standard library scripts.
Download IronPython.StdLib.2.7.8.zip, extract everything to a folder
And add this to your code:
ScriptEngine engine = Python.CreateEngine();
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\yourLibFolder");
engine.SetSearchPaths(searchPaths);
Upvotes: 1