boost-python

Boost Python: Error when passing variable by reference in a function

痞子三分冷 提交于 2019-12-13 02:44:24
问题 I would like to understand why the following function does not work in python: #include<boost/python.hpp> #include<iostream> #include<string> void hello(std::string& s) { std::cout << s << std::endl; } BOOST_PYTHON_MODULE(test) { boost::python::def("hello", hello); } When I import library into python import test test.hello('John') I get an error: test.hello(str) did not match C++ signature: hello(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > {lvalue})

can not import numpy in boost-python

风流意气都作罢 提交于 2019-12-13 00:52:48
问题 I am trying out boost-python. However, even a simple hello world doesn't work. #define BOOST_PYTHON_STATIC_LIB #include <boost/python/detail/wrap_python.hpp> #include "numpy/arrayobject.h" #include <boost/python.hpp> void init_numpy() { import_array(); } int main() { Py_Intialize(); init_numpy(); } It gives error ImportError: numpy.core.multiarray failed to import But if I open my IPython, and run import numpy.core.multiarray , it runs fine. What part am I getting worng? 回答1: I solved the

Python is unable to import library compiled with boost_python

故事扮演 提交于 2019-12-12 19:33:26
问题 I have the following sample program: // src/main.cpp #include <boost/python.hpp> char const* func() { return "String"; } BOOST_PYTHON_MODULE(bridge) { boost::python::def("func", func); } When built using the following CMakeLists.txt, no compiler errors are given: project(bridge) cmake_minimum_required(VERSION 3.5) set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src) set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY

how to use asyncio with boost.python?

我只是一个虾纸丫 提交于 2019-12-12 15:37:59
问题 Is it possible to use Python3 asyncio package with Boost.Python library? I have CPython C++ extension that builds with Boost.Python . And functions that are written in C++ can work really long time. I want to use asyncio to call these functions but res = await cpp_function() code doesn't work. What happens when cpp_function is called inside coroutine? How not get blocked by calling C++ function that works very long time? NOTE : C++ doesn't do some I/O operations, just calculations. 回答1: What

communicate between python and C++

天大地大妈咪最大 提交于 2019-12-12 15:21:32
问题 I want to create a python module which can have its functions called from a C++ class and call c++ functions from that class i have looked at boost however it hasn't seemed to make any sense it refers to a shared library (which i have no idea how to create) and i cant fallow the code they use in examples (it seems very confusing) here is their hello world tutorial (http://www.boost.org/doc/libs/1_55_0b1/libs/python/doc/tutorial/doc/html/index.html#python.quickstart) Following C/C++ tradition,

Boost Python wrapper and OpenCv argument error with cv::Mat

拟墨画扇 提交于 2019-12-12 13:43:33
问题 I have a C++ class that I've wrapped with Boost Python. One of the class methods takes in two cv::Mat s like so: MyClass::do_something(cv::Mat input, cv::Mat output) The functionality I've provided with python includes the above method, a constructor, and a few print methods. The initialization and print methods (for debugging) work well in both C++ and the Python wrapper: obj = MyClass(arg1, arg2, arg3) obj.print_things() These calls complete successfully. I am running into trouble with the

Boost.Python.ArgumentError: python str not converted to std::string

霸气de小男生 提交于 2019-12-12 10:51:37
问题 I get an error I can't make sense of trying to wrap a rather simple c++ class via Boost.Python. First, the class: #include <boost/python.hpp> #include <boost/shared_ptr.hpp> #include <vector> #include <string> class token { public: typedef boost::shared_ptr<token> ptr_type; static std::vector<std::string> empty_context; static std::string empty_center; token(std::string& t = empty_center, std::vector<std::string>& left = empty_context, std::vector<std::string>& right = empty_context) : center

Point FindBoost CMAKE to boost_python Windows 10, VS 2017

回眸只為那壹抹淺笑 提交于 2019-12-12 09:27:13
问题 My high level goal is to install the BGSlibrary which requires boost for python on Windows 10 using Visual Studio 2017. I compiled opencv and boost (1.64.0) from source using cmake 3.9.0. During cmake for BGSLIBRARY I get $ cmake -DBGS_PYTHON_SUPPORT=ON -DBOOST_ROOT="C:/Program Files/boost_1_64_0/" .. -- BGSLIBRARY WITH PYTHON SUPPORT: ON -- OpenCV library status: -- version: 3.3.0 CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.9/ Modules/FindBoost.cmake:1877 (message): Unable to

Extracting unsigned char from array of numpy.uint8

☆樱花仙子☆ 提交于 2019-12-12 08:46:38
问题 I have code to extract a numeric value from a python sequence, and it works well in most cases, but not for a numpy array. When I try to extract an unsigned char, I do the following unsigned char val = boost::python::extract<unsigned char>(sequence[n]); where sequence is any python sequence and n is the index. I get the following error: TypeError: No registered converter was able to produce a C++ rvalue of type unsigned char from this Python object of type numpy.uint8 How can I successfully

Installing PythonMagick with boost on osx

元气小坏坏 提交于 2019-12-12 04:39:19
问题 I am trying to install PythonMagick following these instructions. https://gist.github.com/tomekwojcik/2778301 When I get to $ make I get this error Making all in pythonmagick_src CXX libpymagick_la-_DrawableFillRule.lo _DrawableFillRule.cpp:3:10: fatal error: 'boost/python.hpp' file not found #include <boost/python.hpp> ^ 1 error generated. make[1]: *** [libpymagick_la-_DrawableFillRule.lo] Error 1 make: *** [all-recursive] Error 1 How do I get PythonMagick installed in my project? Any way