From imre.i.horvath at gmail.com Mon Jul 20 10:36:22 2015 From: imre.i.horvath at gmail.com (imre.i.horvath at gmail.com) Date: Mon, 20 Jul 2015 08:36:22 +0000 Subject: [C++-sig] =?utf-8?q?distributing_python_with_embedded_app?= Message-ID: <55acb45f.0a6dc20a.819ec.ffffcf2d@mx.google.com> Hi! I?ve compiled python 3.4.2 with vs2013, it works. I want to use python script for google oauth2 authentication. If i run the script from command line with my custom build python instance, it works. I zipped the lib folder of my python installation, put the zip in the same folder as my .exe file, it works, until i use the standard python modules. When i want to run this script embedded with boost python (exec_file), it can not find the modules installed by hand (oauth2client etc) How can I redistribute my custom python with all the modules installed? Thanks in advance: Imre Horvath -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at maddisoj.co.uk Thu Jul 30 18:53:50 2015 From: james at maddisoj.co.uk (James Maddison) Date: Thu, 30 Jul 2015 17:53:50 +0100 Subject: [C++-sig] Member overloads signature not matching C++ signature Message-ID: <55BA569E.5080905@maddisoj.co.uk> I am trying to bind a C++ class but python is reporting there is no matching signature for two of the methods which are I am trying to bind using the member function overloads macro. The class looks like so: struct path { path(); path(double line_width); void move_to(point_t point); void line_to(point_t point); void curve_to(std::array&& points) void curve_to(const std::array& points); void fill(context& ctx, bool close = true) const; void stroke(context& ctx, bool close = true) const; }; I'm not sure if this is the best way but I have made a thin wrapper around the class such that the curve_to method can be called with a tuple: struct path_wrapper : path { using path::path; void curve_to(const py::tuple& points) { path::curve_to({ py::extract(points[0]), py::extract(points[1]), py::extract(points[2]), }); } }; The function overloads are being defined as such: BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( path_fill_overloads, fill, 1, 2 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( path_stroke_overloads, stroke, 1, 2 ); I then bind the class as such: py::class_("Path") .def(py::init()) .def("move_to", &path::move_to) .def("line_to", &path::line_to) .def("curve_to", &path_wrapper::curve_to) .def("fill", &path::fill, path_fill_overloads()) .def("stroke", &path::stroke, path_stroke_overloads()); I am binding the other classes named throughout this process, but I have omitted their actual class_ calls from this message. When I make a call to the methods in python I recieve the following error: Traceback (most recent call last): File "/home/james/projects/imgen/patterns/triangles.py", line 46, in draw path.stroke(context) Boost.Python.ArgumentError: Python argument types in Path.stroke(Path, Context) did not match C++ signature: stroke(path {lvalue}, context {lvalue}) stroke(path {lvalue}, context {lvalue}, bool) I am really confused as the signatures appear to match. I suspect I've broken the converters with my wrapper class but I am unsure how to fix it. Thank you. From stefan at seefeld.name Fri Jul 31 17:04:37 2015 From: stefan at seefeld.name (Stefan Seefeld) Date: Fri, 31 Jul 2015 11:04:37 -0400 Subject: [C++-sig] Member overloads signature not matching C++ signature In-Reply-To: <55BA569E.5080905@maddisoj.co.uk> References: <55BA569E.5080905@maddisoj.co.uk> Message-ID: <55BB8E85.2000706@seefeld.name> On 30/07/15 12:53 PM, James Maddison wrote: > I am trying to bind a C++ class but python is reporting there is no > matching signature for two of the methods which are I am trying to > bind using the member function overloads macro. > > The class looks like so: > > struct path { > path(); > path(double line_width); > > void move_to(point_t point); > void line_to(point_t point); > void curve_to(std::array&& points) > void curve_to(const std::array& points); > void fill(context& ctx, bool close = true) const; > void stroke(context& ctx, bool close = true) const; > }; > > I'm not sure if this is the best way but I have made a thin wrapper > around the class such that the curve_to method can be called with a > tuple: > > struct path_wrapper : path { > using path::path; > > void curve_to(const py::tuple& points) > { > path::curve_to({ > py::extract(points[0]), > py::extract(points[1]), > py::extract(points[2]), > }); > } > }; I think this could be simplified a bit: You don't need an entire new type to wrap a single member function. Just use a free (non-member) function definition with an additional first argument standing for "this": void curve_to(path &p, py::tuple const &points) { ... } and then use "curve_to" instead of "&path_wrapper::curve_to" when binding it. > > The function overloads are being defined as such: > > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( > path_fill_overloads, fill, 1, 2 > ); > > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( > path_stroke_overloads, stroke, 1, 2 > ); > > I then bind the class as such: > > py::class_("Path") > .def(py::init()) > .def("move_to", &path::move_to) > .def("line_to", &path::line_to) > .def("curve_to", &path_wrapper::curve_to) > .def("fill", &path::fill, path_fill_overloads()) > .def("stroke", &path::stroke, path_stroke_overloads()); > > I am binding the other classes named throughout this process, but I > have omitted their actual class_ calls from this message. > > When I make a call to the methods in python I recieve the following > error: > > Traceback (most recent call last): > File "/home/james/projects/imgen/patterns/triangles.py", line > 46, in draw > path.stroke(context) > Boost.Python.ArgumentError: Python argument types in > Path.stroke(Path, Context) > did not match C++ signature: > stroke(path {lvalue}, context {lvalue}) > stroke(path {lvalue}, context {lvalue}, bool) > > I am really confused as the signatures appear to match. I suspect I've > broken the converters with my wrapper class but I am unsure how to fix > it. I suspect the problem is that you "context" argument is a non-const reference. If it were const, the binding would work. If it has to be non-const, you need to supply a call-policy. (Unfortunately I'm not sure how to do that with the BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS macro. But given that you only have two overloads, perhaps you can avoid the macro alltogether, just to get this working. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin...