[C++-sig] embedded python ?

mad city madcitymann at gmail.com
Fri Apr 3 21:49:39 CEST 2009


Thanks. Good advice.

>From the quickstart project, the embedded.cpp file function


void exec_file_test(std::string const &script)
{
    std::cout << "running file " << script << "..." << std::endl;

    // Run a python script in an empty environment.
    python::dict global;
    python::object result = python::exec_file(script.c_str(), global,
global);

    // Extract an object the script stored in the global dictionary.
    BOOST_TEST(python::extract<int>(global["number"]) ==  42);

    std::cout << "success!" << std::endl;
}

calls my python script file - parseLogs.py which starts with

import os.path
import stat
import csv
import re
import pickle
import operator
import time
import msvcrt
from optparse import OptionParser
import sys

The 'import' call throws the exception - ImportError: __import__ not found.
I'm looking into the PyInitialize() and how the interpreter gets loaded.

Thanks.



On Fri, Apr 3, 2009 at 1:55 PM, Stefan Seefeld <seefeld at sympatico.ca> wrote:

> mad city wrote:
>
>> 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
>>
>> ImportError: __import__ not found
>>
>
> 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.
>
> 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.
>
> Regards,
>      Stefan
>
> --
>
>     ...ich hab' noch einen Koffer in Berlin...
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090403/a38d4401/attachment.htm>


More information about the Cplusplus-sig mailing list