[C++-sig] Embedding and calling extended python commands

Satyajit Sarangi ssarangi123 at gmail.com
Fri Nov 30 16:32:05 CET 2007

Hi Stefan,
            The errors which I get are as follows:

Python File 1:

import smallPython

a = smallPython



C:\Python25>testpy test.py
running file test.py...
y:\private\my documents\ssarangi\my documents\visual studio
2005\projects\smallpython\smallpython\main.cpp(166): Python Error detected
in function 'int __cdecl main(int,char **)'
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import smallPython
ImportError: __import__ not found
1 error detected.

However, I can import the smallPython module directly into the python

Seems like I am missing something and also it shows me an error for the cpp
file when I have the smallPython.pyd and smallPython.lib in the python root
directory. The cpp file is the same as the example getting_started_1.cpp

Cpp File:

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <string>

namespace { // Avoid cluttering the global namespace.

  // A couple of simple C++ functions that we want to expose to Python.
  std::string greet() { return "hello, world"; }
  int square(int number) { return number * number; }

namespace python = boost::python;

// Python requires an exported function called init<module-name> in every
// extension module. This is where we build the module contents.
    // Add regular functions to the module.
    python::def("greet", greet);
    python::def("square", square);

Thanks a lot for the help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20071130/b507e473/attachment.htm>

More information about the Cplusplus-sig mailing list