Hello Ian. The easiest thing would probably be to just use the meta_path
importer feature. This allows you to package up all of the standard library
directly into your compiled host application, and the python runtime will be
able to find them. The steps are pretty simple:
1. Find the standard library files. Default location is usually something like
C:\python27\.
2. Zip that entire folder up into a single zip file. You can optionally omit
files that you know won't be needed at runtime.
3. Add the zip file to your c# project file as an embedded resource (add it to
the project, and then in the file properties make sure it is set to the right
build action).
4. Add a little bit of code to your Python engine startup code. Here is a
simplified example of how I do it (my embedded file was named
"python_27_lib.zip"), but this isn't the only way:
public ScriptEngine CreateEngine()
{
var options = new Dictionary<string, object>();
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(options);
var pyRuntime = new ScriptRuntime(setup);
var engineInstance = Python.GetEngine(pyRuntime);
// use embedded python lib
var asm = this.GetType().Assembly;
var resQuery =
from name in asm.GetManifestResourceNames()
where name.ToLowerInvariant().EndsWith("python_27_lib.zip")
select name;
var resName = resQuery.Single();
var importer = new ResourceMetaPathImporter(asm, resName);
dynamic sys = engineInstance.GetSysModule();
sys.meta_path.append(importer);
sys.path = new List();
return engineInstance;
}
Keith Rome
Senior Consultant and Architect
MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS
Wintellect | 770.617.4016 | [email protected]
www.wintellect.com
-----Original Message-----
From: Ironpython-users
[mailto:[email protected]] On Behalf Of
Ian Gorse
Sent: Tuesday, December 18, 2012 7:27 AM
To: [email protected]
Subject: [Ironpython-users] No module named datetime
Hi list,
I'm new to mailing lists so apologise if this is done incorrectly - I didn't
know how to search the existing archives.
I am still fairly new to IronPython but managed to pick it up quite quickly,
however I have come to a stumbling block.
I have currently developed a C# application that converts data into specific
file formats. I am using IronPython to handle the conversion process which
allows me to create new converters and modifiy existing ones on the fly without
re-complication of the C# application.
Its wonderful and I couldn't be any happier about it.
However, its time to run the application in a production environment.
Once I have my software installed on a test pc (that has no developement tools
installed), executing the software throws the Exception..
'No module named datetime'
And I re-created the error using a simple python script
import datetime
now = datetime.datetime.now()
I guess I could get around it by using he .NET DateTime object but I would
prefer to use the python datetime if I can.
What do I need to do to make this work?
Thanks
_______________________________________________
Ironpython-users mailing list
[email protected]
http://mail.python.org/mailman/listinfo/ironpython-users
_______________________________________________
Ironpython-users mailing list
[email protected]
http://mail.python.org/mailman/listinfo/ironpython-users