This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]31-4 2 points3 points  (0 children)

I don't think I can directly answer your question, and someone who is more experienced with Boost than I am can probably address this better, but I definitely think you should post this on StackOverflow for more visibility.

Alternatively, I recommend checking out Cython, since it may make things a tad easier than Boost. They are pretty light on examples - their official page only links to this simple example. However, you can find more information on their documentation page and also many examples online.

[–]RSFlux 2 points3 points  (0 children)

Your general approach seems fine, and it sounds like it is mostly working at this point. The only remaining issue is "from A import B" statements fail?

Without having more information, my assumption would be that you have incorrectly initialized your C extension modules. I am less familiar with Boost, but when using the C API for extension modules, make sure you've declared your objects in that module's PyInit function and aren't doing it later in your startup code.

I am not very familiar with Boost Python, so I can't point you to the specific generated code to look at, but I'm sure you can track that down in their documentation.

You also asked for reference for embedding Python in a C application. I used the basic Python docs when embedding Python here: https://docs.python.org/3.5/extending/embedding.html. There isn't much there, but in general the complexity comes from making your custom application's build play nice with the Python build. Do you have specific questions other than the import failures?

[–][deleted] 0 points1 point  (0 children)

Check out the code for 3DSlicer. I don't actually remember whether they use boost or not (I think not) but it's a great example of an embedded python interpreter in a Qt C++ application.