Good point! I forgot that I was having the *.py files in a subdirectory.<div><br></div><div>Is it also possible to set the 'current' directory for the engine?</div><div><br></div><div>For instance I would like to have the engine living in a subfolder of my project and then all path's would be relative to this subfolder.</div>
<div><br></div><div>thank you,</div><div>Severin</div><div><br><div class="gmail_quote">On Fri, Jan 30, 2009 at 4:56 PM, Michael Foord <span dir="ltr"><<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="Ih2E3d">Severin wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I'm digging out this thread again.<br>
<br>
I'm trying to run python scripts from C# using the DLR.<br>
<br>
Simple examples work, namely if I have just one function in one python file.<br>
<br>
How does it work when one python file imports from another python file? I get "No module named x" ImportExceptions when trying to compile these python files.<br>
</blockquote>
<br></div>
If you're running them from '.py' source files then you aren't compiling them - you're just executing them from an embedded environment.<br>
<br>
The import machinery should work exactly the same as for CPython, but you may need to setup the initial sys.path depending on how you are executing the scripts.<br>
<br>
You probably need to use the engine.SetSearchPaths method passing in an array with the path to the directory containing the top level Python file (adding any other directories that you need to be able to import from).<br>
<br>
HTH<br>
<br>
Michael<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="Ih2E3d">
<br>
I compile the main-file with 'CreateScriptSourceFromFile'.<br>
<br>
<br>
May be I am using the wrong approach in general. What I have is a bunch of python files that I used with CPython directly so far. Now I want to extend my program with C# (since database handling is much more convenient there) and I want to use the python files that I already have.<br>
<br>
What is the best approach for this scenario?<br>
<br>
Thanks for any kind of hint.<br>
<br>
Severin<br>
<br></div><div class="Ih2E3d">
On Tue, Jan 20, 2009 at 5:37 PM, Michael Foord <<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a> <mailto:<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>>> wrote:<br>
<br>
Renaud Durand wrote:<br>
<br>
Ok, Thank you.<br>
<br>
Does anyone know where could I find an IronPython Assembly<br>
documentation and/or up to date tutorials ?<br>
<br>
<br>
These tutorials are up to date - except for the one specified as<br>
being for IP1:<br>
<br>
<a href="http://www.voidspace.org.uk/ironpython/embedding.shtml" target="_blank">http://www.voidspace.org.uk/ironpython/embedding.shtml</a><br>
<br>
Michael<br>
<br>
<br>
Thank you again.<br>
<br>
2009/1/20 Curt Hagenlocher <<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a><br></div>
<mailto:<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a>> <mailto:<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a><div><div></div><div class="Wj3C7c">
<br>
<mailto:<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a>>>><br>
<br>
<br>
I believe this was valid for a long-ago alpha. For the 2.0<br>
release, you'll want to create an engine by saying<br>
engine = Python.CreateEngine()<br>
<br>
On Tue, Jan 20, 2009 at 7:32 AM, Renaud Durand<br>
<<a href="http://renaud.durand.it" target="_blank">renaud.durand.it</a> <<a href="http://renaud.durand.it" target="_blank">http://renaud.durand.it</a>><br>
<<a href="http://renaud.durand.it" target="_blank">http://renaud.durand.it</a>>@<a href="http://gmail.com" target="_blank">gmail.com</a> <<a href="http://gmail.com" target="_blank">http://gmail.com</a>><br>
<<a href="http://gmail.com" target="_blank">http://gmail.com</a>>> wrote:<br>
<br>
Hi,<br>
<br>
I want to use IronPython function through C#. To do It, I<br>
found a tutorial at<br>
<a href="http://www.ironpython.info/index.php/Hosting_IronPython_2" target="_blank">http://www.ironpython.info/index.php/Hosting_IronPython_2</a>.<br>
But the code does not seem to be updated for IronPython<br>
2.0.<br>
<br>
the code is :<br>
<br>
using System;<br>
using IronPython.Hosting;<br>
using IronPython.Runtime;<br>
using Microsoft.Scripting;<br>
using Microsoft.Scripting.Hosting;<br>
<br>
namespace EmbeddedCalculator<br>
{<br>
public class Engine<br>
{<br>
private ScriptEngine engine;<br>
<br>
public Engine()<br>
{<br>
engine = PythonEngine.CurrentEngine;<br>
}<br>
<br>
public string calculate(string input)<br>
{<br>
try<br>
{<br>
ScriptSource source =<br>
engine.CreateScriptSourceFromString(input, "py");<br>
return source.Execute().ToString();<br>
}<br>
catch<br>
{<br>
return "Error";<br>
}<br>
}<br>
<br>
}<br>
}<br>
// End of code<br>
<br>
When I try to compile it in visual studio, the compiler<br>
could<br>
not find the name "PythonEngine". I have added all the<br>
references to<br>
the needed libraries. So, what am I missing ?<br>
<br>
<br>
Thank you :-).<br>
<br>
-- Renaud Durand<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>><br>
<mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>>><br>
<br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br>
<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>><br>
<mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br></div></div><div class="Ih2E3d">
<mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>>><br>
<br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br>
<br>
<br>
<br>
-- Renaud Durand<br>
------------------------------------------------------------------------<br>
<br>
<br>
<br>
_______________________________________________<br>
Users mailing list<br></div><div class="Ih2E3d">
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> <mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br>
<br>
<br></div><div class="Ih2E3d">
-- <a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
<a href="http://www.voidspace.org.uk/blog" target="_blank">http://www.voidspace.org.uk/blog</a><br>
<br>
<br>
<br>
_______________________________________________<br>
Users mailing list<br></div><div class="Ih2E3d">
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> <mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br>
<br>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br>
</div></blockquote><div><div></div><div class="Wj3C7c">
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br>
</div></div></blockquote></div><br></div>