boost-python

How to package shared objects that python modules depend on?

假如想象 提交于 2021-02-18 11:43:11
问题 I have a python package implemented in C++ that I am distributing using setuptools. My C++ code depends on some shared objects, specifically the boost.python library. How should I distribute these shared objects? At the moment I ask the package user to install the boost C++ libraries separately but I would rather bundle everything in one setuptools distribution to make it easier for him/her. At the moment they must set up the boost libraries and their LD_LIBRARY_PATH environment variable in

How can i declare a Boost.Python C++ Class with PyObjects

邮差的信 提交于 2021-02-17 05:20:53
问题 i want to write a c++ class with PyObjects to access them from Python to reference them with an existing Python object instance. In short words i want to store/manage Python object instances in the C++ class. For example: struct Var { PyObject *Test_1; PyObject *Test_2; }; #include <boost/python.hpp> using namespace boost::python; BOOST_PYTHON_MODULE(Var) { class_<Var>("Var", init<std::string>()) .def_readwrite("Test_1", &Var::value) .def_readwrite("Test_2", &Var::value) ; } in python i want

how can I import [.myfolder.pyfile] as [something else]?

↘锁芯ラ 提交于 2021-02-11 12:47:46
问题 let's say I have project |__ utilities | |__ foo.py | |__ boost_extensions | |__ myclass.cpp | |__ myclass.so | |__ someotherstuff | |__ bar.py | |__ mylib.py | |__ __main__.py Is it possible to do something like this in main .py import .utilities.foo as Foo # this function will pass Foo to C++ and initialize it to a global variable initCppFunction(Foo) I've tried this but it gives me an invalid syntax error (I'm trying to do this due to some problems with importing python modules from boost

How to pass ctypes.POINTER to boost.python

最后都变了- 提交于 2021-02-10 20:31:11
问题 I have following code: old_lib.h: struct DUMMY { // some members }; module.cpp: #include <boost/python.hpp> #include "old_lib.h" namespace py = boost::python; void foo(py::object const& p) { // How to get rid of ctypes.addressof()? static py::object ctypes_addressof = py::import("ctypes").attr("addressof"); DUMMY *ptr = *reinterpret_cast<DUMMY**>(uintptr_t(py::extract<uintptr_t>(ctypes_addressof(p)))); } BOOST_PYTHON_MODULE(module) { py::def("foo", &foo, args("p")); } old_python.py: import

TypeError: __init__() should return None, not 'NoneType' with Python Boost

假如想象 提交于 2021-02-08 09:53:41
问题 cmake file cmake_minimum_required(VERSION 3.13) project(p1) set(CMAKE_CXX_STANDARD 11) FIND_PACKAGE(PythonInterp) if (PYTHONINTERP_FOUND) if (UNIX AND NOT APPLE) if (PYTHON_VERSION_MAJOR EQUAL 3) FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_SUFFIX}) FIND_PACKAGE(PythonInterp 3) FIND_PACKAGE(PythonLibs 3 REQUIRED) else() FIND_PACKAGE(Boost COMPONENTS python) FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs REQUIRED) endif() else() if (PYTHON_VERSION_MAJOR EQUAL 3) FIND_PACKAGE(Boost

Extract in C++ a Python object inherited from C++ Class

一笑奈何 提交于 2021-02-08 06:39:04
问题 I want to export an abstract class from C++(Base) to create an inherited class in Python(Derived) and finally extract that class for create a C++ pointer object(Base*). I find this solution. but it didn't work for me although it compiles, the execution halt with an exception. My code is this: #if PY_MAJOR_VERSION >= 3 # define INIT_MODULE PyInit_module extern "C" PyObject* INIT_MODULE(); #else # define INIT_MODULE initmodule extern "C" void INIT_MODULE(); #endif int main() { PyImport

Extract in C++ a Python object inherited from C++ Class

我与影子孤独终老i 提交于 2021-02-08 06:38:07
问题 I want to export an abstract class from C++(Base) to create an inherited class in Python(Derived) and finally extract that class for create a C++ pointer object(Base*). I find this solution. but it didn't work for me although it compiles, the execution halt with an exception. My code is this: #if PY_MAJOR_VERSION >= 3 # define INIT_MODULE PyInit_module extern "C" PyObject* INIT_MODULE(); #else # define INIT_MODULE initmodule extern "C" void INIT_MODULE(); #endif int main() { PyImport

Undefined symbol in Boost.Python module

帅比萌擦擦* 提交于 2021-02-08 05:38:15
问题 I'm trying to build a small Python extension for a certain instantiation of a templated library, using Boost.Python. This library uses extensively the CGAL library, which integrates fairly well with CMake, that I'm therefore using for my project. Here's the code for my module (python_export.cpp): #include <boost/python.hpp> #include <CGAL/Exact_spherical_kernel_3.h> #include "Sphere_intersecter.h" // header-only typedef CGAL::Exact_spherical_kernel_3 SK; template class Sphere_intersecter<SK>;

boost::python export custom exception and inherit from Python's Exception

浪子不回头ぞ 提交于 2021-02-07 20:06:15
问题 The accepted answer to boost::python Export Custom Exception shows how to export a custom exception class from C++, and Boost.Python custom exception class shows how to export an exception class that inherits from Python's Exception. How can I do both? That is expose an exception class that has custom methods to retrieve information and also have that class be derived from Python's Exception. 回答1: A workable solution, suggested by Jim Bosch on the C++-sig list, is to use composition instead

boost python: tie lifetime of argument to returned value using return_internal_reference

梦想的初衷 提交于 2021-02-07 09:19:09
问题 I begin learning to use boost python and have a rookie question. I would like to write a function that can tie the lifetime of its argument to its results, such that when I call r = func(a) , the argument a will never be destroyed if I still have a reference of r . The documentation suggests using return_internal_reference call policy for this type of request. But does this require r to be an internal reference of a , as the name suggested? In the (over-simplified) example below, suppose I