Note that there are some explanatory texts on larger screens.

plurals
  1. POImporting python boost module
    text
    copied!<p>I built a DLL in VS2010 with boost::python to export some function to a python module:</p> <p>myDLL.cpp:</p> <pre><code>std::string greet() { return "hello, world"; } int square(int number) { return number * number; } BOOST_PYTHON_MODULE(getting_started1) { // Add regular functions to the module. def("greet", greet); def("square", square); } </code></pre> <p>Up to here, everything compiles just fine. I then get the myDLL.dll and myDLL.lib file in c:\myDLL\Debug.</p> <p>According to boost doc (http://wiki.python.org/moin/boost.python/SimpleExample), I need to add this to PYTHONPATH, so I added c:\myDLL\Debug to it: PYTHONPATH: C:\Python27;c:\myDLL\Debug;</p> <p>then, from my .py file, I try to import it: </p> <pre><code>import getting_started1 print getting_started1.greet() number = 11 print number, '*', number, '=', getting_started1.square(number) </code></pre> <p>I have also tried from myDLL import getting_started1, and from getting_started1 import *, and all possible combinations of sorts.</p> <p>Can anyone tell me how am I supposed to call my module? Thanks</p> <p>EDIT: According to cgohlke, there should be a getting_started1.pyd somewhere in my PYTHONPATH when I compile in VS? This file is inexistant... Do I have to set somethign different in VS2010? I have a default win32 DLL project. But the boost doc says " If we build this shared library and put it on our PYTHONPATH", isn't a shared library on windows a DLL? ergo, the DLL should be in the PYTHONPATH?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload