boost-python

Boost.Python examples, Windows 7 x64, “ImportError: DLL load failed: The specified module could not be found.”

大憨熊 提交于 2019-11-30 15:45:09
问题 I've spent last 2 days trying to launch examples from Boost.Python with the "ImportError: DLL load failed: The specified module could not be found" error, while trying to load compiled (using bjam) pyd modules. I was using Windows 7 x64, Python 2.7 x64 with Boost 1.47. I've followed up different answers on StackOverflow and other sites incl. fresh installs (Python 32 and 64 bit, Boost precompiled), manual Boost's libraries building, DLL checks with dependency walker and so on, with no luck. I

Boost.Python examples, Windows 7 x64, “ImportError: DLL load failed: The specified module could not be found.”

倖福魔咒の 提交于 2019-11-30 15:27:44
I've spent last 2 days trying to launch examples from Boost.Python with the "ImportError: DLL load failed: The specified module could not be found" error, while trying to load compiled (using bjam) pyd modules. I was using Windows 7 x64, Python 2.7 x64 with Boost 1.47. I've followed up different answers on StackOverflow and other sites incl. fresh installs (Python 32 and 64 bit, Boost precompiled), manual Boost's libraries building, DLL checks with dependency walker and so on, with no luck. I registered to share the solution, which worked here and which I hope may help someone, struggling with

Exposing a pointer in Boost.Python

亡梦爱人 提交于 2019-11-30 12:59:38
I have this very simple C++ class: class Tree { public: Node *head; }; BOOST_PYTHON_MODULE(myModule) { class_<Tree>("Tree") .def_readwrite("head",&Tree::head) ; } I want to access the head variable from Python, but the message I see is: No to_python (by-value) converter found for C++ type: Node* From what I understand, this happens because Python is freaking out because it has no concept of pointers. How can I access the head variable from Python? I understand I should use encapsulation, but I'm currently stuck with needing a non-encapsulation solution. Of course, I find the answer ten minutes

Is wrapping C++ library with ctypes a bad idea?

房东的猫 提交于 2019-11-30 12:17:36
I read through the following two threads on wrapping C library and C++ library , I am not sure I get it yet. The C++ library I am working with does use class and template, but not in any over-sophisticated way. What are issues or caveats of wrapping it with ctypes (besides the point that you can do so in pure python etc)? PyCXX , Cython and boost::python are three other choices people mentioned, is there any consensus which one is more suitable for C++? Thanks Oliver For C++ a library to be accessible from Python it must use C export names, which basically means that a function named foo will

How to define a Python metaclass with Boost.Python?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 11:46:39
The Python C API has the PyObject *PyType_Type object, which is equivalent to type in the interpreter. If I want to define a metaclass in C++, how can I set type as one of its bases in Boost.Python? Also, what other things should I take into consideration when defining a Python metaclass in C++? It'd be ideal if there was a Boost.Python solution to this. If not, a solution that uses the Python C API (or a combination of Boost and the C API) is good as well. Since my other classes are exposed with Boost, I'd rather leave SWIG as a last resort. Note: This is actually part of a bigger problem I'm

Boost Python Runtime error when passing object of derived type from python to C++ function expecting a shared_ptr to base type

独自空忆成欢 提交于 2019-11-30 09:49:17
问题 I have a function that takes a std::shared_ptr, and I want to pass an object of Derived type to this function from python. Here's my class definitions: struct AbstractBase { virtual void foo() = 0; }; struct Derived : public AbstractBase { virtual void foo(){ std::cout<<"Derived's foo!"<<std::endl; } }; struct Unrelated { void bar(std::shared_ptr<AbstractBase> base_shared_ptr) { base_shared_ptr->foo(); } }; #endif /* CLASSES_H */ A simple pure C++ example does what I want: int main() { std:

Boost.Python custom exception class

血红的双手。 提交于 2019-11-30 08:11:43
问题 I'm implementing a Python extension module using Boost.Python. The module should define its own custom exception classes that inherit Exception . How do I do that? 回答1: The following function creates a new Python exception class and adds it to the current scope. If it is called in a module initialization function, then it is added to the module. The first argument is the name of the new exception class. The second argument is the type object for the base class of the new exception class; it

ImportError: /usr/lib/libboost_python.so.1.54.0: undefined symbol: PyClass_Type

百般思念 提交于 2019-11-30 05:17:41
问题 I have code written in C++: #include <boost/python.hpp> char const* greet() { return "Yay!"; } BOOST_PYTHON_MODULE(libtest) { using namespace boost::python; def("greet", greet); } Now i want to import this dynamic library to python by: import libtest But I get: ImportError: /usr/lib/libboost_python.so.1.54.0: undefined symbol: PyClass_Type What should I do? My OS is Arch Linux. 回答1: Ok, I have found solution for this problem. The simplest options is to compile by: g++ testing.cpp -I/usr

Exposing a C++ class instance to a python embedded interpreter

倖福魔咒の 提交于 2019-11-30 03:20:27
I am looking for a simple way to expose a C++ class instance to a python embedded interpreter. I have a C++ library. This library is wrapped (using swig for the moment) and I am able to use it from the python interpreter I have a C++ main program which instanciates a Foo class from my library and embeds a python interpreter I would like to expose my C++ world instance of Foo to the python world (and seen as a Foo class). Is this possible, if so, how? I think it's almost like in the first answer of : boost::python::ptr or PyInstance_New usage I guess this means I should use boost.Python to wrap

Boost::Python- possible to automatically convert from dict --> std::map?

拈花ヽ惹草 提交于 2019-11-30 00:30:00
I've got a C++ class, with a member function that can take a small-to-large number of parameters. Lets name those parameters, a-f. All parameters have default values. As a part of the python project I am working on, I want to expose this class to python. Currently, the member function looks something like this: class myClass { public: // Constructors - set a-f to default values. void SetParameters(std::map<std::string, double> &); private: double a, b, c, d, e, f; } void myClass::SetParameters(std::map<std::string, double> const& params) { // Code to iterate over the map, and set any found key