5

I am trying to use numpy module functions in my Python code that i run inside my c# application in VS13.

I'm doing this to import the module:

ScriptEngine pyEngine = IronPython.Hosting.Python.CreateEngine();
ScriptScope pyScope = pyEngine.CreateScope();

pyEngine.Execute("import numpy", pyScope);

however it says "No module named numpy". I was looking for the solution and found this: How to install numpy and scipy for Ironpython27? Old method doens't work Using Nilsters answer I managed to install numpy and im able to use it when i run ipy from cmd. However i dont know how to use it in my c# app in VS. I've been looking through the files and found

\IronPython 2.7\DLLs\NumpyDotNet.dll

and also:

\IronPython 2.7\Lib\site-packages\numpy\

How do i make it possible for my python code to import numpy?

Community
  • 1
  • 1
Kuczi
  • 357
  • 4
  • 18
  • you can use pythonnet for this. – denfromufa Sep 02 '16 at 13:45
  • Where can i find detailed information about Python.Net and instructions on how to use it in my c# application. I try to reference Python.Reference.dll like this site suggests http://pythonnet.sourceforge.net/readme.html. But cant call PythonEngine.Intialize(). – Kuczi Sep 05 '16 at 07:03
  • if you already have CPython installed then try `pip install pythonnet`, otherwise WinPython comes with pythonnet bundled in it: https://winpython.github.io/ – denfromufa Sep 05 '16 at 15:23
  • you can also build the latest from source: https://github.com/pythonnet/pythonnet – denfromufa Sep 05 '16 at 15:24
  • here is a simple instruction on how to use pythonnet from C#: https://github.com/pythonnet/pythonnet/blob/master/README.md – denfromufa Sep 05 '16 at 15:25
  • I managed to install PythonNet already. I'm wondering if just referencing Python.Runtime.dll in my project is enough. Also when i run the code u sent me i get an error on this line dynamic b = np.array(new List { 6, 5, 4 }, Py.kw("dtype", np.int32)); TypeError : long() argument must be a string or a number, not '0. However the most important thing i need to do is to be able to just run my python script in my app and pass args to it. Could you please give an example on that? – Kuczi Sep 06 '16 at 06:17
  • There is an open issue about `dynamic b = np.array(new List { 6, 5, 4 }, Py.kw("dtype", np.int32))`: https://github.com/pythonnet/pythonnet/issues/249 – denfromufa Sep 06 '16 at 06:51
  • You do not need pythonnet to just run python scripts with args passed. Pythonnet is used for embedding and extending CPython. – denfromufa Sep 06 '16 at 06:55

0 Answers0