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 &#39;current&#39; 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&#39;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">&lt;<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>&gt;</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&#39;m digging out this thread again.<br>
<br>
I&#39;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 &quot;No module named x&quot; ImportExceptions when trying to compile these python files.<br>
</blockquote>
<br></div>
If you&#39;re running them from &#39;.py&#39; source files then you aren&#39;t compiling them - you&#39;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 &nbsp;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 &#39;CreateScriptSourceFromFile&#39;.<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 &lt;<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a> &lt;mailto:<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>&gt;&gt; wrote:<br>

<br>
 &nbsp; &nbsp;Renaud Durand wrote:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Ok, Thank you.<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Does anyone know where could I find an IronPython Assembly<br>
 &nbsp; &nbsp; &nbsp; &nbsp;documentation and/or up to date tutorials ?<br>
<br>
<br>
 &nbsp; &nbsp;These tutorials are up to date - except for the one specified as<br>
 &nbsp; &nbsp;being for IP1:<br>
<br>
 &nbsp; &nbsp;<a href="http://www.voidspace.org.uk/ironpython/embedding.shtml" target="_blank">http://www.voidspace.org.uk/ironpython/embedding.shtml</a><br>
<br>
 &nbsp; &nbsp;Michael<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Thank you again.<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;2009/1/20 Curt Hagenlocher &lt;<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a><br></div>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a>&gt; &lt;mailto:<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a><div><div></div><div class="Wj3C7c">
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a>&gt;&gt;&gt;<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I believe this was valid for a long-ago alpha. &nbsp;For the 2.0<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; release, you&#39;ll want to create an engine by saying<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; engine = Python.CreateEngine()<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; On Tue, Jan 20, 2009 at 7:32 AM, Renaud Durand<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="http://renaud.durand.it" target="_blank">renaud.durand.it</a> &lt;<a href="http://renaud.durand.it" target="_blank">http://renaud.durand.it</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<a href="http://renaud.durand.it" target="_blank">http://renaud.durand.it</a>&gt;@<a href="http://gmail.com" target="_blank">gmail.com</a> &lt;<a href="http://gmail.com" target="_blank">http://gmail.com</a>&gt;<br>

 &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="http://gmail.com" target="_blank">http://gmail.com</a>&gt;&gt; wrote:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hi,<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I want to use IronPython function through C#. To do It, I<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; found a tutorial at<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.ironpython.info/index.php/Hosting_IronPython_2" target="_blank">http://www.ironpython.info/index.php/Hosting_IronPython_2</a>.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; But the code does not seem to be updated for IronPython<br>
 &nbsp; &nbsp; &nbsp; &nbsp;2.0.<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the code is :<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using System;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using IronPython.Hosting;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using IronPython.Runtime;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using Microsoft.Scripting;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using Microsoft.Scripting.Hosting;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; namespace EmbeddedCalculator<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public class Engine<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private ScriptEngine engine;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public Engine()<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; engine = PythonEngine.CurrentEngine;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public string calculate(string input)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScriptSource source =<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; engine.CreateScriptSourceFromString(input, &quot;py&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return source.Execute().ToString();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &quot;Error&quot;;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // End of code<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; When I try to compile it in visual studio, the compiler<br>
 &nbsp; &nbsp; &nbsp; &nbsp;could<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; not find the name &quot;PythonEngine&quot;. I have added all the<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; references to<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the needed libraries. So, what am I missing ?<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thank you :-).<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- &nbsp; &nbsp; &nbsp; &nbsp;Renaud Durand<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Users mailing list<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;&gt;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; <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>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Users mailing list<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br></div></div><div class="Ih2E3d">
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;&gt;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <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>
 &nbsp; &nbsp; &nbsp; &nbsp;--  &nbsp; &nbsp; &nbsp; &nbsp;Renaud Durand<br>
 &nbsp; &nbsp; &nbsp; &nbsp;------------------------------------------------------------------------<br>
<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;_______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Users mailing list<br></div><div class="Ih2E3d">
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp; <br>
<br>
<br></div><div class="Ih2E3d">
 &nbsp; &nbsp;--  &nbsp; &nbsp;<a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
 &nbsp; &nbsp;<a href="http://www.voidspace.org.uk/blog" target="_blank">http://www.voidspace.org.uk/blog</a><br>
<br>
<br>
<br>
 &nbsp; &nbsp;_______________________________________________<br>
 &nbsp; &nbsp;Users mailing list<br></div><div class="Ih2E3d">
 &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp;<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>
 &nbsp;<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>