boost-python

How to solve __imp___Py_NoneStruct Error in Boost.Python?

孤街醉人 提交于 2019-12-23 19:13:04
问题 I am trying to link C++ and Python with Boost.Python. I have Visual Studio 2012 Express Version, Python 2.7, and Boost 1.54. I followed the instructions of Boost official website to install Boost on my machine, which means I followed these steps: I download the prebuilt binary and install it at C:\local\boost_1_54\ . I run bjam b2 --build-dir=C:\local\boost_1_54 toolset=msvc11.0 --build-type=complete stage . Then I had such operations in property panel: Add C:\local\boost_1_54\; C:\Python27

Error compiling Boost.Python quickstart

别等时光非礼了梦想. 提交于 2019-12-23 18:17:39
问题 I've been trying to compile the Boost.Python 'quickstart' ($BOOST_PATH\libs\python\examples\quickstart) examples and have run into an issue. First, my environment: OS: Windows 7 Ultimate 64 bit Python version: 2.7 32 bit C++ Compiler: VC10 Boost version: 1.53.0 Initially, I had issues compiling the Boost.Python library files but happened upon this Stack Overflow thread which solved my issue by explaining how to set include directories in VS2010 and point the boost compile to my python

Compiled .so for boost python cannot find module

落爺英雄遲暮 提交于 2019-12-23 09:58:26
问题 I am trying to wrap c++ code into python, just one class to export with two functions. I compiled to to map.so and when I try to import map get error like noise Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: ./map.so: undefined symbol: _ZTIN5noise6module6ModuleE My c++ directory looks like (noise is dowwnloaded source code and all code is inside src) / map.cpp real_map.h real_map.cpp noise/ src/ .h and .cpp and new directory my CMakeLists.txt looks like

boost::python::enum large uint32 crash

一世执手 提交于 2019-12-23 04:47:49
问题 I am trying to wrap a c++ enum using boost::python (boost 1.58). An enum is of type uint32_t and all values are wrapped without problem except large numbers, starting at 0x4000 0000. An attempt to wrap enum value (uint32) of 0x4000 0000 lead to crash at enum.hpp, line 95 (boost 1.58). i observe this behaviour with VS2012 (win7). Any ideas? example: enum EnumName: uint32_t { valueOK = 0x20000000, valueCrash = 0x40000000 }; boost::python::enum_<EnumName>("EnumName") .value("valueOK", valueOK)

Boost Python No to_python for std::unique_ptr

雨燕双飞 提交于 2019-12-23 03:43:13
问题 I have a problem with boost.python that I can't solve. I tried to expose a class including a function that returns a std::unique_ptr . The signature looks like: std::unique_ptr<MyClass> myFunc() const; I exposed the function and got the following error when calling myFunc() in python: TypeError: No to_python (by-value) converter found for C++ type: std::unique_ptr<MyClass, std::default_delete<MyClass> > I tried to solve the error by also exposing the pointer with the following code: class_

ld: library not found for -lboost_python on MacOS

删除回忆录丶 提交于 2019-12-23 02:59:16
问题 On Mac, I want to build the example Boost.Python code hello.cpp #include <boost/python.hpp> char const* greet() { return "hello, world"; } BOOST_PYTHON_MODULE(hello_ext) { using namespace boost::python; def("greet", greet); } I installed the Boost.Python with brew install boost-python --with-python3 And I compiled the hello.cpp by g++ -fpic -c -L/usr/local/Cellar/boost/1.67.0_1/lib `python3.6m-config --includes --libs --ldflags` hello.cpp There is a hello.o file generated. And generate .so

How to convert C++ objects to boost::python::object?

巧了我就是萌 提交于 2019-12-23 02:05:48
问题 bp::extract converts bp::object to specific type. The question is how to do vice-verse? Let's presume I have a PointContainer and Point classes. I need to have a function with such signature bp::object get_point(const PointContainer &, const bp::object & input); It should check if input argument is an integer. In that case it returns a reference to Point instance from PointContainer with corresponding index. If it is not an integer then function checks if the input is a slice object (ex.

Catch creation of instance attributes of boost::python-wrapped classes from c++

旧巷老猫 提交于 2019-12-22 12:30:32
问题 I am wrapping (many) c++ classes with boost::python. If I mistype the attribute name when assigning it from a python script, python silently creates new instance attribute, which is never what I indent. Is there a way to catch such events (and raise exception?)? I've seen a few posts on the web on the topic, but none of them seemd to give a definitive answer; I was trying to override __setattr__ & friends, but I was not able to get it right; plus I was concerned about possible performance

C++ destructor calling of boost::python wrapped objects

不羁岁月 提交于 2019-12-22 11:37:08
问题 Does boost::python provide any guarantee when the C++ destructor of a wrapped object is called considering the moment of reaching the zero reference count of the corresponding python object? I am concerned about a C++ object that opens a file for writing and performs the file closing in its destructor. Is it guaranteed that the file is written when all python references to the object are deleted or out of scope? I mean: A=MyBoostPythonObject() del A # Is the C++ destructor of

Boost.python overloaded constructor for numpy array and python list

天涯浪子 提交于 2019-12-22 10:22:54
问题 Given a C++ class exposed with Boost.Python, how do I expose two constructors: one that takes a numpy array, and another that takes a python list? 回答1: I'm not a 100% on what you mean, but I'm assuming that you want to have a constructor taking a Python list and another one taking a numpy array. There are a couple of ways to go about this. The easiest way is by using the make_constructor function and overloading it: using boost; using boost::python; shared_ptr<MyClass> CreateWithList(list lst