Thanks. Good advice.<br><br>From the quickstart project, the embedded.cpp file function<br><br><br>void exec_file_test(std::string const &script)<br>{<br> std::cout << "running file " << script << "..." << std::endl;<br>
<br> // Run a python script in an empty environment.<br> python::dict global;<br> python::object result = python::exec_file(script.c_str(), global, global);<br><br> // Extract an object the script stored in the global dictionary.<br>
BOOST_TEST(python::extract<int>(global["number"]) == 42);<br> <br> std::cout << "success!" << std::endl;<br>}<br><br>calls my python script file - parseLogs.py which starts with <br>
<br>import os.path<br>import stat<br>import csv<br>import re<br>import pickle<br>import operator<br>import time<br>import msvcrt<br>from optparse import OptionParser<br>import sys<br><br>The 'import' call throws the exception - ImportError: __import__ not found. I'm looking into the PyInitialize() and how the interpreter gets loaded.<br>
<br>Thanks.<br><br><br><br><div class="gmail_quote">On Fri, Apr 3, 2009 at 1:55 PM, Stefan Seefeld <span dir="ltr"><<a href="mailto:seefeld@sympatico.ca">seefeld@sympatico.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">mad city wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Just starting out with boost-python. I have a python script that I want to call from C++ code. I have the quickstart example working. I'm running into a problem. The python script I'm calling includes import statements - for example 'import os', and these are causing an exception<br>
<br>
ImportError: __import__ not found <br>
</blockquote>
<br></div>
Not having seen your code, I'd suggest you start by looking at the existing tests that use the functionality you want. In this case, this means the 'import' and 'exec' tests in boost/libs/python/test.<br>
<br>
It's generally most likely to get help if you provide some details, such as a chunk of code that we could run to reproduce the issue.<br>
<br>
Regards,<br>
Stefan<br><font color="#888888">
<br>
-- <br>
<br>
...ich hab' noch einen Koffer in Berlin...<br>
<br>
_______________________________________________<br>
Cplusplus-sig mailing list<br>
<a href="mailto:Cplusplus-sig@python.org" target="_blank">Cplusplus-sig@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/cplusplus-sig" target="_blank">http://mail.python.org/mailman/listinfo/cplusplus-sig</a><br>
</font></blockquote></div><br>