boost-python

Initializing Cython objects with existing C Objects

非 Y 不嫁゛ 提交于 2019-12-17 19:51:07
问题 C++ Model Say I have the following C++ data structures I wish to expose to Python. #include <memory> #include <vector> struct mystruct { int a, b, c, d, e, f, g, h, i, j, k, l, m; }; typedef std::vector<std::shared_ptr<mystruct>> mystruct_list; Boost Python I can wrap these fairly effectively using boost::python with the following code, easily allowing me to use the existing mystruct (copying the shared_ptr) rather than recreating an existing object. #include "mystruct.h" #include <boost

boost python: how to call a C++ virtual function

别来无恙 提交于 2019-12-13 18:09:38
问题 I have python embedded in a C++ application. The C++ calls python and passes it as an argument a C++ object. that object has some virtual functions and can be a base class for some derived class. How do I make boost::python understand that it's a virtual function? consider the following: in C++: class Base { public: virtual void func(); } class Derived { public: virtual void func(); } BOOST_PYTHON_MODULE(module_api) { class_<Base>("Base") .def("func", &Base::func); // ?? what should I put

How to override __setattr__ in a wrapped class (from C++)?

元气小坏坏 提交于 2019-12-13 16:27:21
问题 Using boost::python , I have been able to wrap a class ( Node ) which has some virtual functions, and it's been a hoot, but now I'm trying to override setattr/getattr for the class. I've got boost::python to call my own setattr implementation, but I can't figure out how to avoid the recursion that happens. So I have a Node class, and I want to be able to write: node1.param1 = 5 # Call node.SetParam node1.plain_member = 7 # Call object.__setattr__ So far, I have (very abridged): namespace bpy

Including System Libraries with Bjam for Boost.Python

孤街浪徒 提交于 2019-12-13 14:29:08
问题 This is probably a really basic question but I haven't been able to find a solution anywhere. I'm building a Python extension in C++ using Boost.Python and need to link my project with libpcap, but nothing I specify seems to point bjam to the correct location. Pcap is currently installed to /usr/local/include (OS X 10.9) and I can import it with XCode, Make, or any other build system. However when I try to run bjam it gives me the linker error "Undefined symbols for architecture x86_64." I

Boost Python portability concerns

青春壹個敷衍的年華 提交于 2019-12-13 13:28:58
问题 I have a dll written in C++ that I want to export to Python for running regression and unit-testing (it's just easier to maintain and run the regression with Python). To this purpose I want to use Boost.Python to export the main API of the dll so it will be usable in Python. My assemblies look as follows: MyLibrary.dll //main API C++ library MyLibrary.pyd //a thin dll project containing only the BOOST_PYTHON_MODULE export definitions (dependant on MyLibrary.dll) ... //other C++ dll files that

Why is PyGILState_Release throwing Fatal Python Errors

梦想与她 提交于 2019-12-13 12:02:37
问题 ANSWERED Ok, I solved this issue. Its all in how you initialize the thread state. You don't need to use ReleaseLock at all. Simply add InitThreads call to your module definition: BOOST_PYTHON_MODULE(ModuleName) { PyEval_InitThreads(); ... } Ok, I have attempted to diagnose this problem for hours and poured through what seems like every example on the web. Getting tired now so I may be missing something obvious but here is what is happening: I am wrapping a library in boost python. I am

boost python, using a namespace other than main global

两盒软妹~` 提交于 2019-12-13 07:06:49
问题 I am embedding python in my C++ application using boost python. I am a C++ programmer, with very limited knowledge of Python. I have a C++ class, PyExpression . Each instance of this class has a string expStr , which is a short user-entered (at runtime) python program, that is executed by calling boost::python::exec . Briefly, I have this set up as: //import main and its globals bp::object main = bp::import("__main__"); bp::object main_namespace = main.attr("__dict__"); where main and main

How to wrap functions overloaded by type?

爱⌒轻易说出口 提交于 2019-12-13 04:43:42
问题 Suppose there is a class MyArray which implements an array of SomeType . It is written in C++ and wrapped into Python using boost::python. BOOST_PYTHON_MODULE(my_array_module) { class_<MyArray>("MyArray") // a few '.def's ... .def("__getitem__", ???) ; } The __getitem__ function in Python can either take an index and return SomeType value, or take a slice object and return slice. There is how to deal with functions overloaded in C++ to wrap them into different Python functions. There is how

How to use 'boost_python-vc110-mt-gd-1_54.lib' in C++?

天大地大妈咪最大 提交于 2019-12-13 04:33:05
问题 I am trying to use BoostPython to write a program in C++. My presettings are: a. Win32 Console Application. b. Property->C/C++->General->Additional Include Directories->C:\Python27\include;C:\Program Files\boost\boost_1_54_0; c. Property->Linker->General->Additional Library Directions->C:\Python27\libs; d. Microsoft Visual Studio 2012 Express Version + Python 27 + Boost 1.54 And my code is like follows: #include <boost/python.hpp> using namespace boost::python; int main( int argc, char **

Error in boost-python nested namespace exporting code

旧时模样 提交于 2019-12-13 03:44:22
问题 I am working on exporting two classes class zoo (extzoo and intzoo namespaces), class animal (extanim and intanim namespaces)" methods which are defined within two level nested namespaces. I want to expose these methods to Python interpreter from where I can access them. I have written code, created a shared library but when I import it into a python I get an error. I will appreciate your guidance on this. I have followed the answer given on the following link in similar context of exposing C