boost-python

TypeError: No to_python (by-value) converter found for C++ type

半腔热情 提交于 2020-01-24 01:46:25
问题 I'm trying to expose my C++ Classes to Python using Boost.Python. Here is a simplyfied version of what I'm trying to do: struct Base { virtual ~Base() {}; virtual char const *Hello() { printf("Base.Hello\n"); return "Hello. I'm Base."; }; }; struct Derived : Base { char const *Hello() { printf("Derived.Hello\n"); return "Hello. I'm Derived."; }; Base &test() { printf("Derived.test\n"); // ... // After some calculation, we get result reference `instance' // `instance' can be an instance of

dependencies between compiled modules in python

时光怂恿深爱的人放手 提交于 2020-01-16 18:01:33
问题 Let's say I have two modules in a python project that are written in C++ and exposed with boost::python. mod1.hpp #ifndef MOD1_HPP #define MOD1_HPP #include <boost/python.hpp> int square(int x); #endif mod1.cpp #include "mod1.hpp" using namespace boost::python; int square(int x) { return x*x; } BOOST_PYTHON_MODULE (mod1) { def("square",&square); } mod2.hpp #ifndef MOD2_HPP #define MOD2_HPP #include <iostream> #include <boost/python.hpp> #include "mod1.hpp" int myfunc(int x); #endif mod2.cpp

Exposing OpenCV-based C++ function with Mat/Numpy conversion to Python

谁说我不能喝 提交于 2020-01-13 18:38:12
问题 I've ran into a problem trying to expose dynamic C++ library functions, linked to OpenCV and using OpenCV's Mat datatype, to Python 2.7 with the use of Numpy ndarray . I've come up with a solution similar to lightalchemist's solution here and I've also tried using boost::python and boost::numpy (also linked to Python 2.7) described in this SO question. Right now I'm sticking with the former. I've got to a point where I can load the module in iPython, and I see a function I'm trying to port

How to use boost::python::iterator with return_internal_reference?

天大地大妈咪最大 提交于 2020-01-13 17:25:10
问题 I have a class Type which cannot be copied nor it contains default constructor. I have second class A that acts as a set of the above classes. This second class gives access via iterators and my iterator has dereference operator: class A { class iterator { [...] public: Type & operator*() { return instance; } private: Type instance; } [...] }; Now to expose that I wrote a boost::python code that looks like that: class_<A>("A", [...]) .def("__iter__", iterator<A, return_internal_reference<> >(

Set a python variable to a C++ object pointer with boost-python

你说的曾经没有我的故事 提交于 2020-01-13 05:34:08
问题 I want to set a Python variable from C++ so that the C++ program can create an object Game* game = new Game(); in order for the Python code to be able to reference this instance (and call functions, etc). How can I achieve this? I feel like I have some core misunderstanding of the way Python or Boost-Python works. The line main_module.attr("game") = game is in a try catch statement, and the error (using PyErr_Fetch) is "No to_python (by-value) converter found for C++ type: class Game". E.g.

Boost python container, iterator and item lifetimes

此生再无相见时 提交于 2020-01-05 07:19:07
问题 I am trying to expose C++ container to Python. I have: class Container { std::auto_ptr<Iterator> __iter__(); }; class Iterator { Container & parent; Item __next__(); }; class Item { Container & parent; }; Item class internally references data that exists in Container. Iterator which returned Item instance doesn't have to exist for Item to be usable. c = Container() for i in c: store = i print store In above code I would expect to get Container , Iterator and few Item instances. When it

Sending Python function as Boost.Function argument

房东的猫 提交于 2020-01-04 14:03:32
问题 Things are getting complicated in my world of trying to mesh Python code with my C++. Essentially, I want to be able to assign a callback function to be used after an HTTP call receives a response, and I want to be able to do this from either C++ or Python. In other words, I want to be able to call this from C++: http.get_asyc("www.google.ca", [&](int a) { std::cout << "response recieved: " << a << std::endl; }); and this from Python: def f(r): print str.format('response recieved: {}', r)

Run python in C++ [closed]

为君一笑 提交于 2020-01-03 16:56:49
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I have an application written in C++ and a testing system (also in C++). Testing system is pretty complicated and hard to change (I want to make only small changes). My class looks like this: class Derived : public Base { public: void somefunc(const AnotherClass& file) { } };

Using Boost::Python::Object causes linker errors

隐身守侯 提交于 2020-01-03 01:21:47
问题 So, I'm attempting to embed Python into C++. I have gotten fairly far in, and have been able to do basic things like run strings of Python. As soon as I tried to use Boost::Python::Object I began getting these 4 linker errors. I built boost using BJAM with Boost 1.54.0 and Python 2.7.5. Python Lib Build Commands: bootstrap .\b2 toolset=msvc-10.0 --with-python Minimal Code Example : #include <boost/python.hpp> #include <iostream> int main(int, char **) { Py_Initialize(); PyRun_SimpleString(

MSVC - boost::python static linking to .dll (.pyd)

和自甴很熟 提交于 2020-01-02 22:04:14
问题 I got a VS10 project. I want to build some C++ code so I can use it in python. I followed the boost tutorial and got it working. However VS keeps to link boost-python-vc100-mt-gd-1_44.lib but it's just a wrapper which calls boost-python-vc100-mt-gd-1_44.dll. That's why I need to copy the .dll with my .dll(.pyd) file. So I want to link boost:python statically to that .dll(.pyd) file. But I just can't find any configuration option in VS or in the compiler and linker manual. The weirdest thing