C++ Learning Community Forum
August 01, 2010, 03:01:12 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Boost Python  (Read 487 times)
biggoron
C++ Freak
***
Posts: 351


View Profile
« on: April 09, 2009, 03:32:48 AM »

I don't understand how to get my compiled module into the Python interpreter. I compiled this code to a shared object target with g++ on Ubuntu 8.10 to a path in sys.path

Code:
#include <boost/python.hpp>
using namespace boost::python;

char const* greet()
{
   return "hello, world";
}

BOOST_PYTHON_MODULE(hello_ext)
{
    def("greet", greet);
}

Then, I opened IDLE and tried "import hello_ext" (hello_ext not found) and tried using File -> Open Module... -> foo.so, but that produced an error.
What do I do to get the module into Python?

Thanks.
Logged

kccc
I think we have an answer to C-Man's question in his title.
Geek
*****
Posts: 147


View Profile
« Reply #1 on: April 09, 2009, 04:02:08 AM »

You have to append the location where this 'module' is located to the path search list.
In IDLE do the following:
n = your file's absolute directory surrounded by quotes
import sys
sys.path.append(n)
import hello_ext
voila!

for example:
Quote
n = "c:/temp"
sys.path.append(n)
import hello ext
« Last Edit: April 09, 2009, 04:05:56 AM by kccc » Logged
biggoron
C++ Freak
***
Posts: 351


View Profile
« Reply #2 on: April 09, 2009, 04:16:02 AM »

Thanks for the input, but foo.so is already in a path in sys.path. I can see it in IDLE's path navigator.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!