<div>Sorry for long delay,</div>
<div> </div>
<div>I've tried below code (Setting pythonpath environment variable)</div>
<div>and then initialize python interpreter but the embedded python interpreter did not get the newly assigned PYTHONPATH. </div>
<div>I ve looked at the sys.path in python code (that is run by the embedded interpreter) and it behaved according to older pythonpath.</div>
<div> </div>
<div>Setting environment variable seemed to be correct. </div>
<div>Does py_initialize run in another thread so it starts before setting the environment var?</div>
<div><font color="#008000" size="2">
<p>// add custom plib.zip archive to pythonpath</p></font><font size="2">
<p></p></font><font color="#0000ff" size="2">if</font><font size="2">(!::getenv(</font><font color="#800000" size="2">"PYTHONPATH"</font><font size="2">))
<p>{ </p>
<p>::putenv(</p></font><font color="#800000" size="2">"PYTHONPATH=.;.\\plib.zip"</font><font size="2">);
<p>} </p>
<p></p></font><font color="#0000ff" size="2">else</font><font size="2"> ::putenv(</font><font color="#800000" size="2">"PYTHONPATH=%PYTHONPATH%;.\\plib.zip"</font><font size="2">);</font></div>
<div><font size="2">
<p>std::cout << </p></font><font color="#800000" size="2">"PYTHONPath Set to: "</font><font size="2"> << ::getenv(</font><font color="#800000" size="2">"PYTHONPATH"</font><font size="2">) << std::endl << </font><font color="#800000" size="2">"And Again: "</font><font size="2">;</font>
<p><font size="2">system(</font><font color="#800000" size="2">"echo %PYTHONPATH%"</font><font size="2">);</font></p><font size="2"><font size="2">
<p>Py_Initialize();</p></font></font></div>
<div> </div>
<div> </div>
<div> </div>
<div>Regards,<br><br></div>
<div class="gmail_quote">On Fri, Feb 8, 2008 at 2:08 AM, Bronner, Gregory <<a href="mailto:gregory.bronner@lehman.com">gregory.bronner@lehman.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">I've done this the rather old-fashioned way.</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Basically, what I do is:</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Step 1:</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Embed Python:</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"> if(!::getenv("PYTHONHOME"))<br> {<br> ::putenv("PYTHONHOME=<Whatever>");<br> }<br> if(!::getenv("PYTHONPATH"))<br>
{<br> ::putenv("PYTHONPATH=.");<br> }<br> <br> Py_SetProgramName("leaktester");<br> Py_InitializeEx(0);</font></span><span><font face="Arial" color="#0000ff" size="2"><br> init_memoryhoginterface(); // This initializes your SWIG module <br>
PyRun_SimpleString("print 'HELLO FROM PYTHON'"); //<--- OR you can do something else here like run a file</font></span></div>
<div><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div><span><font face="Arial" color="#0000ff" size="2">Step 2: </font></span></div>
<div><span><font face="Arial" color="#0000ff" size="2">Extend python to talk back to your C++ code. </font></span></div>
<div><span><font face="Arial" color="#0000ff" size="2">I use one giant SWIG module (see init function above)</font></span></div>
<div><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div><span><font face="Arial" color="#0000ff" size="2">SWIG allows you to finely control what you expose to python, so you don't wind up exposing the whole C++ API.</font></span></div>
<div><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div><span><font face="Arial" color="#0000ff" size="2"> </font></span></div>
<div dir="ltr" align="left"><br></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"> </font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"> </font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div><br>
<div lang="en-us" dir="ltr" align="left">
<hr>
<font face="Tahoma" size="2"><b>From:</b> Furkan Kuru [mailto:<a href="mailto:furkankuru@gmail.com" target="_blank">furkankuru@gmail.com</a>] <br><b>Sent:</b> Thursday, February 07, 2008 6:06 PM<br><b>To:</b> <a href="mailto:python-list@python.org" target="_blank">python-list@python.org</a><br>
<b>Subject:</b> Re: embedded python in c++ packaging<br></font><br></div>
<div>
<div></div>
<div class="Wj3C7c">
<div></div>
<div>I do not have access to my development machine right now.</div>
<div>but is it enough adding just a simple line at the top of my main python file 'sys.path.append("modules.zip")' before importing any other modules?<br> </div>
<div><span class="gmail_quote">On 2/7/08, <b class="gmail_sendername">Gabriel Genellina</b> <<a href="mailto:gagsl-py2@yahoo.com.ar" target="_blank">gagsl-py2@yahoo.com.ar</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">En Thu, 07 Feb 2008 16:18:57 -0200, Joshua Kugler <<a href="mailto:jkugler@bigfoot.com" target="_blank">jkugler@bigfoot.com</a>><br>
escribió:<br>> Furkan Kuru wrote:<br>>><br>>> I have been developing an application in C++ that embeds Python<br>>> interpreter. It takes advantage of too many modules from Python.<br>>> When I want to package this application, I need to add too many files<br>
>> (.pyc) from Python/lib folder together with Python25.dll.<br>>> Is there a way to pack these .pyc files to a zip file and redirect<br>>> Python25.dll to that zip file?<br>><br>> That is effectively what py2exe does with the modules required by the<br>
> main<br>> application. It takes all the required modules and puts them in a<br>> library.zip file. You might take a look at how it does it.<br><br>Using py2exe has an additional advantage, it recursively scans all modules<br>
looking for dependencies.<br>Once you know the required set of modules, you can bundle them in a .zip<br>file and add its full path into sys.path (the absolute path including<br>filename and .zip extension). Python does look into the .zip searching for<br>
modules.<br><br>--<br>Gabriel Genellina<br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div><br><br clear="all">
<br>-- <br>Furkan Kuru </div></div></div>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. -------- IRS Circular 230 Disclosure: Please be advised that any discussion of U.S. tax matters contained within this communication (including any attachments) is not intended or written to be used and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein. </blockquote>
</div><br><br clear="all"><br>-- <br>Furkan Kuru