boost-python

Building Boost.Python

耗尽温柔 提交于 2019-12-03 13:35:28
I am trying to build Boost.Python according to the instructions on the official website. My OS is Windows 7 64-bit, the compiler is MSVC11, the boost is 1.54. =================== Install Boost ================== To install basic Boost, I downloaded the boost library from its website, unzip it to my local disk. The path is C:\local\boost_1_54_0 . =============== Install Boost.Python =============== I then find that Boost.Python need to be built separately. So I followed the Boost.Python instruction . =============== Install Boost.Build ================ And at stage 3.1.2, Boost.Build is

How to reinitialise an embedded Python interpreter?

我的梦境 提交于 2019-12-03 10:34:44
问题 I'm working on embedding Python in our test suite application. The purpose is to use Python to run several tests scripts to collect data and make a report of tests. Multiple test scripts for one test run can create global variables and functions that can be used in the next script. The application also provides extension modules that are imported in the embedded interpreter, and are used to exchange some data with the application. But the user can also make multiple test runs. I don't want to

Passing Python list to C++ vector using Boost.python

不问归期 提交于 2019-12-03 09:53:39
问题 How do I pass a Python list of my object type ClassName to a C++ function that accepts a vector<ClassName> ? The best I found is something like this: example. Unfortunately, the code crashes and I can't seem to figure out why. Here's what I used: template<typename T> void python_to_vector(boost::python::object o, vector<T>* v) { try { object iter_obj = object(handle<>(PyObject_GetIter(o.ptr()))); return; for (;;) { object obj = extract<object>(iter_obj.attr("next")()); // Should launch an

running c++ code from python

﹥>﹥吖頭↗ 提交于 2019-12-03 07:18:38
I want to execute a code helloword.cpp which takes in some argument from console parses those arguments and then prints "hello world" in the console. Now, I want to parse these arguments from a python scripts parsearguments.py So for example: def parse_arguments: ...# some code return arguments Now, how do i communicate between python and c++. I have been reading and see that cython, boost python are the options but I have a hard time finding the right simple hello world example. Any suggestions will be appreciated. Thanks How about passing whatever text you generate with Python into the

Exposing C++ functions, that return pointer using Boost.Python

放肆的年华 提交于 2019-12-03 06:10:04
问题 I want to expose the following C++ function to Python using Boost.Python: int* test1() { return new int(42); } // Now exposing the function with Boost.Python BOOST_PYTHON_MODULE(libtest1) { using namespace boost::python; def("test1", test1); } When I try to compile this library the error occurs due to (it's my guess) Boost.Python don't know, how to convert int* to PyObject. I think what needs to be done is to define conversion structure, something like this: template<class T> struct int_ptr

Wrapping arrays in Boost Python

坚强是说给别人听的谎言 提交于 2019-12-03 04:26:58
问题 I have a series of C++ structures I am trying to wrap using boost python. I've run into difficulties when these structures contain arrays. I am trying to do this with minimal overhead and unfortunately I can't make any modifications to the structs themselves. So for instance say I have struct Foo { int vals[3]; }; I would like to be able to access this in python as follows: f = Foo() f.vals[0] = 10 print f.vals[0] Right now I am using a series of get/set functions which works but is very

Build Boost with multiple Python versions

孤者浪人 提交于 2019-12-03 04:25:12
问题 I use several versions of Python on my computer : 2.6.6 , 2.7.6 and 2.7.9 . When I compile Boost with boost-python, I have to give the Python to use in argument. If I want compatibility, have I to compile Boost for each Python version ? (it's quite huge !) Or is there a way to use only one build of Boost with several python versions ? 回答1: The official Python development cycle does not describe the stability of the application binary interface (ABI) between releases. For releases before

Passing Python list to C++ vector using Boost.python

喜欢而已 提交于 2019-12-03 01:30:01
How do I pass a Python list of my object type ClassName to a C++ function that accepts a vector<ClassName> ? The best I found is something like this: example . Unfortunately, the code crashes and I can't seem to figure out why. Here's what I used: template<typename T> void python_to_vector(boost::python::object o, vector<T>* v) { try { object iter_obj = object(handle<>(PyObject_GetIter(o.ptr()))); return; for (;;) { object obj = extract<object>(iter_obj.attr("next")()); // Should launch an exception if it cannot extract T v->emplace_back(extract<T>(obj)); } } catch(error_already_set) { PyErr

How to reinitialise an embedded Python interpreter?

淺唱寂寞╮ 提交于 2019-12-03 00:06:55
I'm working on embedding Python in our test suite application. The purpose is to use Python to run several tests scripts to collect data and make a report of tests. Multiple test scripts for one test run can create global variables and functions that can be used in the next script. The application also provides extension modules that are imported in the embedded interpreter, and are used to exchange some data with the application. But the user can also make multiple test runs. I don't want to share those globals, imports and the exchanged data between multiple test runs. I have to be sure I

Configuring Visual Studio to work with Boost.Python and Python 3

こ雲淡風輕ζ 提交于 2019-12-02 01:39:50
I had Microsoft Visual Studio Community 2013 (Version 12.0.31101.00 Update 4) and Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017) on my PC with Windows 10 Pro. In order to try examples with Boost.Python I downloaded boost 1.64.0 and build libraries by b2 with options --with-python --toolset=msvc --build-type=complete . As a result I have the following files: boost_python3-vc120-mt-1_64.dll boost_python3-vc120-mt-1_64.lib boost_python3-vc120-mt-gd-1_64.dll boost_python3-vc120-mt-gd-1_64.lib libboost_python3-vc120-mt-1_64.lib libboost_python3-vc120-mt-gd-1_64.lib libboost_python3-vc120-mt-s-1_64.lib