Jump to content
  • Advertisement
Sign in to follow this  
h3ro

Problems with boost.python

This topic is 3447 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working on making an easier way to add new things to my program, so I decided to create support for python scripting. Getting python to work turned out to be a lot more work then I initially thought. I have installed python and built the needed boost libraries and compiled the example, but I cant get the example to run Here is the code I use to create the .dll file
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>

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

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("greet", greet);
}

The dll file is named hallo_ext.dll and is placed in the same directory as the python file. Here is the code in the python file:
import hello_ext

print hello_ext.greet()
raw_input("Press return to close this window...")


Error outputted from the python file: ImportError: No module named hello_ext. Does anyone know what I am doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Your DLL is called hallo_ext.dll but you're trying to import hello_ext? If that was just a typo I would check that Python's module search path includes the current directory. Try print(sys.path) in your script somewhere.

Share this post


Link to post
Share on other sites
rename hello_ext.dll to hello_ext.pyd Should solve your problem :) Also make sure the dll is either in site-packages or the same directory as your script.

Share this post


Link to post
Share on other sites
I changed the name of the dll to pyd, but now I get a different error.
The dll is in the same folder as the script.

ImportError: Dll load failed. The specified module could not be found.

I have never written a python script before, so it might be something very basic that is wrong. Any ideas?

Share this post


Link to post
Share on other sites
Did you fix the hallo/hello mismatch? (If it even existed at all, that is - be sure you type in here exactly what you see.)

Share this post


Link to post
Share on other sites
The hallo/hello typo is only in the post. It was a typo when I wrote it up, the files are named correctly.

All the code is from the example that comes with boost, so I cant understand why it is not working.

Share this post


Link to post
Share on other sites
Not that I have done this myself, but did you follow the steps on the next page of that tutorial. I would somehow expect that you get both a binary dll and a python module since it would be strange for python to understand a binary file... (but I'm a total noob in this and might try it if you work it out :))

Share this post


Link to post
Share on other sites
There have been a couple of recent releases for Python so it may be the case that the C API has changed. Which version of Python are you using and are you sure Boost.Python generates DLLs with the correct function signatures?

This is a guess, but it's something you should be sure of anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by the_edd
There have been a couple of recent releases for Python so it may be the case that the C API has changed.

Yep, the Python C API changes for every minor release (eg. 2.5 to 2.6). This means that native-code compiled extensions have to be built individually against each version. h3ro has to make sure that the python.h on his compiler's path is for the same version of Python that is trying to import the module. (If there is only 1 Python installation, obviously this won't be the problem.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!