[Ironpython-users] Embedding numpy in C#

David Rinck dir2104 at columbia.edu
Fri Dec 16 02:15:09 CET 2011

>From the interactive python window I can import numpy and use it just fine.

Within C# however, I am having troubles getting it to import correctly.

I'm using:
string programPath = Path.Combine(rootDir, (string)args[0]);
Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
ScriptEngine engine = Python.CreateEngine(options);
List argList = new List();
ScriptScope sys = Python.GetSysModule(engine);
sys.SetVariable("argv", argList);
var sp = engine.GetSearchPaths();
sp.Add(@"c:\Program Files\IronPython2.7.1");
sp.Add(@"c:\Program Files\IronPython 2.7.1\DLLs");
sp.Add(@"c:\Program Files\IronPython 2.7.1\Lib");
sp.Add(@"c:\Program Files\IronPython 2.7.1\Lib\site-packages");
ScriptSource source = engine.CreateScriptSourceFromFile(programPath);
int result = source.ExecuteProgram();

The python file:

import sys
sys.path.append(r'c:\Program Files\IronPython2.7.1')
sys.path.append(r'c:\Program Files\IronPython 2.7.1\DLLs')
sys.path.append(r'c:\Program Files\IronPython 2.7.1\Lib')
sys.path.append(r'c:\Program Files\IronPython 2.7.1\Lib\site-packages')
print "Running!"
import numpy

My response in the console window is as follows:

Command line arguments ['program.py']
File "c:\Program Files\IronPython 2.7.1\Lib\os.py", line 754
bs = b""

SyntaxError: invalid syntax

I also tried this with Python 2.7 and had the same result. Where am I going wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20111215/a3ef86c7/attachment.html>

More information about the Ironpython-users mailing list