From adam.preble at gmail.com Tue Jan 1 10:26:39 2013 From: adam.preble at gmail.com (Adam Preble) Date: Tue, 1 Jan 2013 03:26:39 -0600 Subject: [C++-sig] RAII for the GIL in Boost.Python? In-Reply-To: <50DCBBB5.7703.323D1560@s_sourceforge.nedprod.com> References: <50DCBBB5.7703.323D1560@s_sourceforge.nedprod.com> Message-ID: Oh I understand that. When they got the Dynamic Language Runtime down, they opened up the gates for that. That being said, Python.NET choked up on that test too. I don't think it's using the DLR though. Really I only give it as something of a final acceptance test for being able to work between one language and Python. And this isn't to nag on Boost and C++ because I can satisfy that criteria with it; it just takes a lot of diplomacy with the GIL. Actually, the more I think of the GIL as being a mutex that I could use Boost's lock structures on, the more fond of the idea I get. Having a recursive lock would have solved a lot of problems, or at least it would have moved me on to the next ones. ;) Anyways professionally I'm stuck with Python.NET because some folks still have some native code they wanted to use. That takes IronPython out of active consideration. Unfortunately I could never find out what all the native stuff was they insisted on keeping. In some cases I've been able to circumvent the callback issue by using events. Those work fine for some reason. On Thu, Dec 27, 2012 at 3:20 PM, Niall Douglas wrote: > > Thing is, .NET has a full IDL interop with COM shim and a well > specified threading model. In other words, it provides lots of > support for mixing up lots of different languages, so getting > multiple language interop working on .NET (or even COM) is vastly > easier than anywhere else. > > Niall > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rohan.preacher.smith at gmail.com Tue Jan 1 15:33:25 2013 From: rohan.preacher.smith at gmail.com (Rohan Smith) Date: Wed, 02 Jan 2013 00:33:25 +1000 Subject: [C++-sig] Additional tutorials on building a Boost::Python module? Message-ID: <50E2F3B5.8000706@gmail.com> Can anyone point me towards any tutorials on building a boost::python module using Mingw/GCC for Python 3? I'm able to invoke bjam as per [1], but it fails when it gets up to the "copy hello.py"[3] command, which causes the rest of it to fail. Attempting to copy the .py beforehand results in it being unable to find a path and quitting with exit status 3. I've had some success with [2] but hit a brick wall at the "initPointless()" line of "Creating a Module", presumably because of a change between the version used in that tutorial and 1.52.0. [1] http://www.boost.org/doc/libs/1_52_0/libs/python/doc/tutorial/doc/html/python/hello.html [2] http://members.gamedev.net/sicrane/articles/EmbeddingPythonPart1.html [3] copy hello.py The syntax of the command is incorrect. copy /b + this-file-does-not-exist-A698EE7806899E69 "hello.py" "bin\hello.t est\gcc-mingw-4.7.2\debug\hello.py" ...failed copy hello.py bin\hello.test\gcc-mingw-4.7.2\debug\hello.py... ...removing hello.py ...skipped hello for lack of hello.py... -- Cheers, Rohan From hapopen at gmail.com Fri Jan 4 16:26:44 2013 From: hapopen at gmail.com (simon zhang) Date: Fri, 4 Jan 2013 23:26:44 +0800 Subject: [C++-sig] compile some code with boost.python by mingw in win7-64bit In-Reply-To: References: Message-ID: sorry.I just have a holiday and forget to reply to this message. I have solved this problem. This is a problem about compiled in the 64bit system and seted up included library. 2012/12/31 Blair Hall > The comments here may be helpful > > http://ctrl-dev.com/2012/02/compiling-boost-python-with-mingw > > I would try to get the example working first without the IDE (ie > follow the boost.python documentation), because boost needs to build > libraries (unless you downloaded them pre-built). The IDE just makes > an already complicated problem more complicated. > > NOTE > > 1: that the boost examples do not seem to work 100% as described in > the documentation. I have found that, with mingw, the necessary > libraries do get built, but you need to make sure they are available > when running the program (e.g., the boost build process for the > examples tries to test things after they have bgeen built, but this > fails because the libraries cannot be located at run time). On the > contrary, using msvc9 things seem to work much better. > > 2: the boost embedding example does not seem to work (either with > mingw or msvc). There are references to this problem already from > other people. > > On Mon, Dec 31, 2012 at 1:27 AM, simon zhang wrote: > > > > I decided to make my program compatible with windows environment.But I > > have very little programming experience on windows.There are some errors > > need help. > > > > Environment: > > > > os: win7-64bit, > > ide: codeblocks12.11, > > python: Python 2.7.3 Windows X86-64 Installer (Windows AMD64 / Intel 64 / > > X86-64 binary [1] -- does not include source) > > compiler: mingw that come from codeblocks installation package. > > boost: boost1.52 > > > > I only copy and test this "hello" code that come from > > ".\boost_1_52_0\libs\python\example\tutorial" > > > > Code: > > > > #include > > #include > > #include > > > > char const* greet() > > { return "hello, world"; } > > > > BOOST_PYTHON_MODULE(hello_ext) > > { > > using namespace boost::python; > > def("greet", greet); > > } > > > > using namespace std; > > int main() > > { > > cout << "Hello world!" << endl; > > return 0; > > } > > > > Error info: > > > > mingw32-g++.exe -Wall -fexceptions -g -ID:\boost\include\boost-1_52 > > -IC:\Python27\include -c E:\project\snail-MW\test1\main.cpp -o > > obj\Debug\main.o > > mingw32-g++.exe -LD:\boost\lib\ -LC:\Python27\libs -o > bin\Debug\test1.exe > > obj\Debug\main.o -static > > obj\Debug\main.o: In function `inithello_ext': > > E:/project/snail-MW/test1/main.cpp:11: undefined reference to > > `boost::python::detail::init_module(char const*, void (*)())' > > obj\Debug\main.o: In function `ZNK5boost6python9type_info4nameEv': > > D:/boost/include/boost-1_52/boost/python/type_id.hpp:165: undefined > > reference to `boost::python::detail::gcc_demangle(char const*)' > > obj\Debug\main.o: In function > > `ZNK5boost6python15to_python_valueIRKPKcEclES5_': > > > > > D:/boost/include/boost-1_52/boost/python/converter/builtin_converters.hpp:161: > > undefined reference to > `boost::python::converter::do_return_to_python(char > > const*)' > > ................ > > > > It have also do some errors that only compile by the command of "bjam > > toolset=gcc variant=release " in the station > > ".\boost_1_52_0\libs\python\example\tutorial". > > > > _______________________________________________ > > Cplusplus-sig mailing list > > Cplusplus-sig at python.org > > http://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumeet.jauhar at gmail.com Tue Jan 8 10:43:43 2013 From: sumeet.jauhar at gmail.com (Sumeet Jauhar) Date: Tue, 8 Jan 2013 17:43:43 +0800 Subject: [C++-sig] Boost Python quickstart examples error Message-ID: Hi , when i try running the example under C:\boost_1_50_0\libs\python\ example\quickstart i get the following error and my python file gets removed ( which is quite annoying ) . I am using Python 3.3 & Boost 1.50 on a Windows 7 OS . How do i fix this ? C:\boost_1_50_0\libs\python\example\quickstart>bjam toolset=msvc --verbose-test test > error_log error_log: ...patience... ...patience... ...found 1662 targets... ...updating 11 targets... copy test_extending.py The syntax of the command is incorrect. copy /b + this-file-does-not-exist-A698EE7806899E69 "test_extending.py" "bin\test_ext.test\msvc-10.0\debug\threading-multi\test_extending.py" ...failed copy test_extending.py bin\test_ext.test\msvc-10.0\debug\threading-multi\test_extending.py... ...removing test_extending.py compile-c-c++ bin\msvc-10.0\debug\threading-multi\extending.obj extending.cpp msvc.link.dll bin\msvc-10.0\debug\threading-multi\extending.pyd Creating library bin\msvc-10.0\debug\threading-multi\extending.lib and object bin\msvc-10.0\debug\threading-multi\extending.exp msvc.manifest.dll bin\msvc-10.0\debug\threading-multi\extending.pyd ...skipped test_ext for lack of test_extending.py... msvc.link bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe LINK : warning LNK4001: no object files specified; libraries used LINK : error LNK2001: unresolved external symbol _mainCRTStartup bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe : fatal error LNK1120: 1 unresolved externals call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul link /NOLOGO /INCREMENTAL:NO /DEBUG /MACHINE:X86 /subsystem:console /out:"bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe" /LIBPATH:"C:\Python33\libs" @"bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe.rsp" if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL% ...failed msvc.link bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.pdb... ...removing bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.pdb ...skipped test_embed.run for lack of test_embed.exe... ...failed updating 3 targets... ...skipped 4 targets... ...updated 4 targets... -------------- next part -------------- An HTML attachment was scrubbed... URL: From themiwi at users.sourceforge.net Wed Jan 16 21:00:09 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Wed, 16 Jan 2013 21:00:09 +0100 Subject: [C++-sig] Wrapping a non-copyiable static instance in bp::object Message-ID: <50F706C9.3050506@users.sourceforge.net> Dear all I struggle to find a way in which I can wrap a static instance in a bp::object without copying it. The goal is to have object identity for this static instance: struct A { /*...*/ static A static_a; }; a A::a; bp::object static_instance() { static bp::object* result = new bp::object(A::static_a); // [1] return *result; } Wrapping A and static_instance with Boost.Python is no problem, and everything works as expected, however the A::static_a that is being passed to bp::object() at [1] is being copied, which defeats the whole purpose. Anybody has an idea how achieve this? Thanks! Cheers Michael From wmamrak at gmail.com Wed Jan 16 22:29:17 2013 From: wmamrak at gmail.com (Wojciech Mamrak) Date: Wed, 16 Jan 2013 22:29:17 +0100 Subject: [C++-sig] Wrapping a non-copyiable static instance in bp::object In-Reply-To: <50F706C9.3050506@users.sourceforge.net> References: <50F706C9.3050506@users.sourceforge.net> Message-ID: Hi, bp::object static_instance() { static bp::object* result = new bp::object(boost::ref(A::static_a)); return *result; } Instead of exposing a function static_instance in your module, you can alternatively add a variable to your module's scope: scope sc; sc.attr("static_a") = boost::ref(A::static_a); //no copy here regards 2013/1/16 Michael Wild : > Dear all > > I struggle to find a way in which I can wrap a static instance in a > bp::object without copying it. The goal is to have object identity for > this static instance: > > struct A { > /*...*/ > static A static_a; > }; > > a A::a; > > bp::object static_instance() > { > static bp::object* result = new bp::object(A::static_a); // [1] > return *result; > } > > Wrapping A and static_instance with Boost.Python is no problem, and > everything works as expected, however the A::static_a that is being > passed to bp::object() at [1] is being copied, which defeats the whole > purpose. > > Anybody has an idea how achieve this? Thanks! > > Cheers > > Michael > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From themiwi at users.sourceforge.net Sun Jan 20 19:48:46 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Sun, 20 Jan 2013 19:48:46 +0100 Subject: [C++-sig] Wrapping a non-copyiable static instance in bp::object In-Reply-To: References: <50F706C9.3050506@users.sourceforge.net> Message-ID: <50FC3C0E.3020201@users.sourceforge.net> I knew (hoped, really) there would be a simple solution! Thanks, it works beautifully. Michael PS: Sorry, I posted earlier, but didn't notice that I got rejected because I used the wrong sender address... On 01/16/2013 10:29 PM, Wojciech Mamrak wrote: > Hi, > > bp::object static_instance() > { > static bp::object* result = new bp::object(boost::ref(A::static_a)); > return *result; > } > > Instead of exposing a function static_instance in your module, you can > alternatively add a variable to your module's scope: > > scope sc; > sc.attr("static_a") = boost::ref(A::static_a); //no copy here > > regards > > > 2013/1/16 Michael Wild : >> Dear all >> >> I struggle to find a way in which I can wrap a static instance in a >> bp::object without copying it. The goal is to have object identity for >> this static instance: >> >> struct A { >> /*...*/ >> static A static_a; >> }; >> >> a A::a; >> >> bp::object static_instance() >> { >> static bp::object* result = new bp::object(A::static_a); // [1] >> return *result; >> } >> >> Wrapping A and static_instance with Boost.Python is no problem, and >> everything works as expected, however the A::static_a that is being >> passed to bp::object() at [1] is being copied, which defeats the whole >> purpose. >> >> Anybody has an idea how achieve this? Thanks! >> >> Cheers >> >> Michael > From themiwi at users.sourceforge.net Tue Jan 22 22:18:31 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Tue, 22 Jan 2013 22:18:31 +0100 Subject: [C++-sig] to_python converter and make_getter Message-ID: <50FF0227.7040802@users.sourceforge.net> Dear all I have defined a to_python converter following http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters. Everything is fine and dandy, however what bugs me is having to specify a return_value_policy() for every make_getter call. Looking through the sources it seems that I should be able to tell make_getter what the default policy should be by somehow specializing default_member_getter_policy and default_datum_getter_policy. However, is this the right way to go, or should I attack the problem at a lower level, e.g. by specializing default_getter_by_ref? Or should I directly specialize make_getter? Michael From talljimbo at gmail.com Tue Jan 22 23:27:01 2013 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 22 Jan 2013 17:27:01 -0500 Subject: [C++-sig] to_python converter and make_getter In-Reply-To: <50FF0227.7040802@users.sourceforge.net> References: <50FF0227.7040802@users.sourceforge.net> Message-ID: <50FF1235.8050904@gmail.com> On 01/22/2013 04:18 PM, Michael Wild wrote: > Dear all > > I have defined a to_python converter following > http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters. > Everything is fine and dandy, however what bugs me is having to specify > a return_value_policy() for every make_getter call. > Looking through the sources it seems that I should be able to tell > make_getter what the default policy should be by somehow specializing > default_member_getter_policy and default_datum_getter_policy. However, > is this the right way to go, or should I attack the problem at a lower > level, e.g. by specializing default_getter_by_ref? Or should I directly > specialize make_getter? > Could you provide a little more information about what you're trying to do and what the error is? I'm surprised that you're having to specify a call-policy manually for return-by-value; I've used by-value to_python converters plenty of times without ever having to do that. Jim From themiwi at users.sourceforge.net Wed Jan 23 06:34:54 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Wed, 23 Jan 2013 06:34:54 +0100 Subject: [C++-sig] to_python converter and make_getter In-Reply-To: <50FF1235.8050904@gmail.com> References: <50FF0227.7040802@users.sourceforge.net> <50FF1235.8050904@gmail.com> Message-ID: <50FF767E.6090403@users.sourceforge.net> On 01/22/2013 11:27 PM, Jim Bosch wrote: > On 01/22/2013 04:18 PM, Michael Wild wrote: >> Dear all >> >> I have defined a to_python converter following >> http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters. >> >> Everything is fine and dandy, however what bugs me is having to specify >> a return_value_policy() for every make_getter call. >> Looking through the sources it seems that I should be able to tell >> make_getter what the default policy should be by somehow specializing >> default_member_getter_policy and default_datum_getter_policy. However, >> is this the right way to go, or should I attack the problem at a lower >> level, e.g. by specializing default_getter_by_ref? Or should I directly >> specialize make_getter? >> > > Could you provide a little more information about what you're trying to > do and what the error is? I'm surprised that you're having to specify a > call-policy manually for return-by-value; I've used by-value to_python > converters plenty of times without ever having to do that. > > Jim > I don't have to do it for functions that return by value, only for static members that I want to wrap in a static property. I put the example here: https://gist.github.com/4602341 Michael From liujz39 at gmail.com Wed Jan 23 08:19:27 2013 From: liujz39 at gmail.com (salinea) Date: Tue, 22 Jan 2013 23:19:27 -0800 (PST) Subject: [C++-sig] Failed to import pyd File When python embed into C++ Message-ID: <1358925567738-4641675.post@n4.nabble.com> I create a pyd File named "testPyd" with boostPython,and then I import the testPyd module into "test.py", it works perfect! But when I embeded the python interpreter into my C++ project and run the "test.py", it comes out a "ImportErr: no module named testPyd". It has confused me for two days and I googled for long time,but I can't find the answer! Anybody here can help me ? Thank you! Here is my test examples: The C++ codes to build the *pyd File* is: Excute.h #ifndef EXCUTE_H_ #define EXCUTE_H_ #include class Excute { public: Excute(){} int getIoReuslt(std::string ioStr); int getSignal(); }; #endif Excute.cpp: #include "Excute.h" #include "Explanation.h" #include int Excute::getIoReuslt(std::string ioStr) { return 1; } int Excute::getSignal() { int i = rand()%2; return i; } BOOST_PYTHON_MODULE(pythonDll) { using namespace boost::python; class_("Excute", init<>()) .def("getIoResult", &Excute::getIoReuslt) .def("getSignal", &Excute::getSignal) ; } Then a pyd File Named pythonDll is created(pythonDll.pyd), Here are the codes in my test.py: test.py: from pythonDll import* h=Excurte() print h.getIoResult("a") print h.getSignal() And this script works perfect in IDLE. And then I embed python into my C++ project,Here are the test codes: #include #include int main(int argc, char* argv[]) { Py_Initialize(); FILE * fp = fopen("$PATH/test.py", "r"); if (fp == NULL) { return 1; } PyRun_SimpleString("execfile($PATH/test.py')"); Py_Finalize(); system("Pause"); return 0; } The result is: Traceback (most recent call last): File "", line 1, in File "$PATH/test.py", line 1, in from pythonDll import* ImportError: No module named pythonDll [19228 refs] -- View this message in context: http://boost.2283326.n4.nabble.com/Failed-to-import-pyd-File-When-python-embed-into-C-tp4641675.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From themiwi at users.sourceforge.net Wed Jan 23 09:23:42 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Wed, 23 Jan 2013 09:23:42 +0100 Subject: [C++-sig] Failed to import pyd File When python embed into C++ In-Reply-To: <1358925567738-4641675.post@n4.nabble.com> References: <1358925567738-4641675.post@n4.nabble.com> Message-ID: On Wed, Jan 23, 2013 at 8:19 AM, salinea wrote: > > I create a pyd File named "testPyd" with boostPython,and then I import the > testPyd module into "test.py", it works perfect! > But when I embeded the python interpreter into my C++ project and run the > "test.py", it comes out a "ImportErr: no module named testPyd". > It has confused me for two days and I googled for long time,but I can't > find > the answer! > Anybody here can help me ? > Thank you! > > Here is my test examples: > The C++ codes to build the *pyd File* is: > Excute.h > > #ifndef EXCUTE_H_ > #define EXCUTE_H_ > #include > > class Excute > { > public: > Excute(){} > int getIoReuslt(std::string ioStr); > int getSignal(); > }; > #endif > > Excute.cpp: > #include "Excute.h" > #include "Explanation.h" > #include > > int Excute::getIoReuslt(std::string ioStr) > { > return 1; > } > > int Excute::getSignal() > { > int i = rand()%2; > return i; > } > > BOOST_PYTHON_MODULE(pythonDll) > { > using namespace boost::python; > class_("Excute", init<>()) > .def("getIoResult", &Excute::getIoReuslt) > .def("getSignal", &Excute::getSignal) > ; > } > Then a pyd File Named pythonDll is created(pythonDll.pyd), > Here are the codes in my test.py: > test.py: > > from pythonDll import* > h=Excurte() > print h.getIoResult("a") > print h.getSignal() > > And this script works perfect in IDLE. > > And then I embed python into my C++ project,Here are the test codes: > #include > #include > > int main(int argc, char* argv[]) > { > Py_Initialize(); > FILE * fp = fopen("$PATH/test.py", "r"); > if (fp == NULL) > { > return 1; > } > PyRun_SimpleString("execfile($PATH/test.py')"); > Py_Finalize(); > > system("Pause"); > > return 0; > } > > The result is: > Traceback (most recent call last): > File "", line 1, in > File "$PATH/test.py", line 1, in > from pythonDll import* > ImportError: No module named pythonDll > [19228 refs] > > Just to help you debug the issue: have you tried putting something like this into your test.py? import sys sys.stderr.write("PYTHONPATH = %s\n"%(":".join(sys.path))) Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From giuseppe.corbelli at copanitalia.com Wed Jan 23 09:16:57 2013 From: giuseppe.corbelli at copanitalia.com (Giuseppe Corbelli) Date: Wed, 23 Jan 2013 09:16:57 +0100 Subject: [C++-sig] to_python converter and make_getter In-Reply-To: <50FF767E.6090403@users.sourceforge.net> References: <50FF0227.7040802@users.sourceforge.net> <50FF1235.8050904@gmail.com> <50FF767E.6090403@users.sourceforge.net> Message-ID: <50FF9C79.7080401@copanitalia.com> On 23/01/2013 06:34, Michael Wild wrote: >>> Dear all >>> >>> I have defined a to_python converter following >>> http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters. >>> >>> Everything is fine and dandy, however what bugs me is having to specify >>> a return_value_policy() for every make_getter call. >>> Looking through the sources it seems that I should be able to tell >>> make_getter what the default policy should be by somehow specializing >>> default_member_getter_policy and default_datum_getter_policy. However, >>> is this the right way to go, or should I attack the problem at a lower >>> level, e.g. by specializing default_getter_by_ref? Or should I directly >>> specialize make_getter? >>> >> >> Could you provide a little more information about what you're trying to >> do and what the error is? I'm surprised that you're having to specify a >> call-policy manually for return-by-value; I've used by-value to_python >> converters plenty of times without ever having to do that. >> >> Jim >> > > I don't have to do it for functions that return by value, only for > static members that I want to wrap in a static property. > > I put the example here: https://gist.github.com/4602341 Since you're wrapping static members why don't you create once and for all a something PyObject* that wraps up what you need? I mean, something like struct A { static std::string staticStdString; static QString staticQString; }; struct A_Wrap { A_Wrap() : staticStdString(A::staticStdString) {} bpy::object staticStdString; } First you register the converter(s). Second you instantiate the one and only A_Wrap. Everytime you access staticStdString just return A_Wrap::staticStdString. -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copanitalia.com From wmamrak at gmail.com Wed Jan 23 12:16:37 2013 From: wmamrak at gmail.com (Wojciech Mamrak) Date: Wed, 23 Jan 2013 12:16:37 +0100 Subject: [C++-sig] Failed to import pyd File When python embed into C++ In-Reply-To: References: <1358925567738-4641675.post@n4.nabble.com> Message-ID: Before initilizing Python interpreter you need to register your module: PyImport_AppendInittab("pythonDll", initpythonDll); regards 2013/1/23 Michael Wild : > On Wed, Jan 23, 2013 at 8:19 AM, salinea wrote: >> >> >> I create a pyd File named "testPyd" with boostPython,and then I import the >> testPyd module into "test.py", it works perfect! >> But when I embeded the python interpreter into my C++ project and run the >> "test.py", it comes out a "ImportErr: no module named testPyd". >> It has confused me for two days and I googled for long time,but I can't >> find >> the answer! >> Anybody here can help me ? >> Thank you! >> >> Here is my test examples: >> The C++ codes to build the *pyd File* is: >> Excute.h >> >> #ifndef EXCUTE_H_ >> #define EXCUTE_H_ >> #include >> >> class Excute >> { >> public: >> Excute(){} >> int getIoReuslt(std::string ioStr); >> int getSignal(); >> }; >> #endif >> >> Excute.cpp: >> #include "Excute.h" >> #include "Explanation.h" >> #include >> >> int Excute::getIoReuslt(std::string ioStr) >> { >> return 1; >> } >> >> int Excute::getSignal() >> { >> int i = rand()%2; >> return i; >> } >> >> BOOST_PYTHON_MODULE(pythonDll) >> { >> using namespace boost::python; >> class_("Excute", init<>()) >> .def("getIoResult", &Excute::getIoReuslt) >> .def("getSignal", &Excute::getSignal) >> ; >> } >> Then a pyd File Named pythonDll is created(pythonDll.pyd), >> Here are the codes in my test.py: >> test.py: >> >> from pythonDll import* >> h=Excurte() >> print h.getIoResult("a") >> print h.getSignal() >> >> And this script works perfect in IDLE. >> >> And then I embed python into my C++ project,Here are the test codes: >> #include >> #include >> >> int main(int argc, char* argv[]) >> { >> Py_Initialize(); >> FILE * fp = fopen("$PATH/test.py", "r"); >> if (fp == NULL) >> { >> return 1; >> } >> PyRun_SimpleString("execfile($PATH/test.py')"); >> Py_Finalize(); >> >> system("Pause"); >> >> return 0; >> } >> >> The result is: >> Traceback (most recent call last): >> File "", line 1, in >> File "$PATH/test.py", line 1, in >> from pythonDll import* >> ImportError: No module named pythonDll >> [19228 refs] >> > > Just to help you debug the issue: have you tried putting something like this > into your test.py? > > import sys > sys.stderr.write("PYTHONPATH = %s\n"%(":".join(sys.path))) > > > Michael > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From talljimbo at gmail.com Wed Jan 23 17:44:28 2013 From: talljimbo at gmail.com (Jim Bosch) Date: Wed, 23 Jan 2013 11:44:28 -0500 Subject: [C++-sig] to_python converter and make_getter In-Reply-To: <50FF767E.6090403@users.sourceforge.net> References: <50FF0227.7040802@users.sourceforge.net> <50FF1235.8050904@gmail.com> <50FF767E.6090403@users.sourceforge.net> Message-ID: <5100136C.4000802@gmail.com> On 01/23/2013 12:34 AM, Michael Wild wrote: > On 01/22/2013 11:27 PM, Jim Bosch wrote: >> On 01/22/2013 04:18 PM, Michael Wild wrote: >>> Dear all >>> >>> I have defined a to_python converter following >>> http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters. >>> >>> Everything is fine and dandy, however what bugs me is having to specify >>> a return_value_policy() for every make_getter call. >>> Looking through the sources it seems that I should be able to tell >>> make_getter what the default policy should be by somehow specializing >>> default_member_getter_policy and default_datum_getter_policy. However, >>> is this the right way to go, or should I attack the problem at a lower >>> level, e.g. by specializing default_getter_by_ref? Or should I directly >>> specialize make_getter? >>> >> >> Could you provide a little more information about what you're trying to >> do and what the error is? I'm surprised that you're having to specify a >> call-policy manually for return-by-value; I've used by-value to_python >> converters plenty of times without ever having to do that. >> >> Jim >> > > I don't have to do it for functions that return by value, only for > static members that I want to wrap in a static property. > > I put the example here: https://gist.github.com/4602341 > Ah, that makes sense. Well, if Giuseppe's idea of just converting the object once doesn't work for you, I'd recommend not specializing any boost::python internals, and just writing a convenience that calls make_getter the way you want: template bp::object my_make_getter(D const & d) { return bp::make_getter( d, bp::return_value_policy() ); } HTH! Jim From themiwi at users.sourceforge.net Wed Jan 23 18:56:54 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Wed, 23 Jan 2013 18:56:54 +0100 Subject: [C++-sig] to_python converter and make_getter In-Reply-To: <5100136C.4000802@gmail.com> References: <50FF0227.7040802@users.sourceforge.net> <50FF1235.8050904@gmail.com> <50FF767E.6090403@users.sourceforge.net> <5100136C.4000802@gmail.com> Message-ID: <51002466.2030406@users.sourceforge.net> On 01/23/2013 05:44 PM, Jim Bosch wrote: > On 01/23/2013 12:34 AM, Michael Wild wrote: >> On 01/22/2013 11:27 PM, Jim Bosch wrote: >>> On 01/22/2013 04:18 PM, Michael Wild wrote: >>>> Dear all >>>> >>>> I have defined a to_python converter following >>>> http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters. >>>> >>>> >>>> Everything is fine and dandy, however what bugs me is having to specify >>>> a return_value_policy() for every make_getter call. >>>> Looking through the sources it seems that I should be able to tell >>>> make_getter what the default policy should be by somehow specializing >>>> default_member_getter_policy and default_datum_getter_policy. However, >>>> is this the right way to go, or should I attack the problem at a lower >>>> level, e.g. by specializing default_getter_by_ref? Or should I directly >>>> specialize make_getter? >>>> >>> >>> Could you provide a little more information about what you're trying to >>> do and what the error is? I'm surprised that you're having to specify a >>> call-policy manually for return-by-value; I've used by-value to_python >>> converters plenty of times without ever having to do that. >>> >>> Jim >>> >> >> I don't have to do it for functions that return by value, only for >> static members that I want to wrap in a static property. >> >> I put the example here: https://gist.github.com/4602341 >> > > Ah, that makes sense. Well, if Giuseppe's idea of just converting the > object once doesn't work for you, I'd recommend not specializing any > boost::python internals, and just writing a convenience that calls > make_getter the way you want: > > template > bp::object my_make_getter(D const & d) { > return bp::make_getter( > d, > bp::return_value_policy() > ); > } > > HTH! > > Jim > Yes, I thought of that too. While this "solves" this case (it certainly is not very discoverable for future maintainers), it does not help in the case of container support. Say I wanted to expose std::vector (or std::vector from the Boost.Python FAQ, for that matter) using the boost::python::vector_indexing_suite. I am perfectly able to create such a list, I can append items, the only thing I can't do is *retrieving* them. It's like a black hole for data ;-) Michael From talljimbo at gmail.com Wed Jan 23 19:03:05 2013 From: talljimbo at gmail.com (Jim Bosch) Date: Wed, 23 Jan 2013 13:03:05 -0500 Subject: [C++-sig] to_python converter and make_getter In-Reply-To: <51002466.2030406@users.sourceforge.net> References: <50FF0227.7040802@users.sourceforge.net> <50FF1235.8050904@gmail.com> <50FF767E.6090403@users.sourceforge.net> <5100136C.4000802@gmail.com> <51002466.2030406@users.sourceforge.net> Message-ID: <510025D9.60100@gmail.com> On 01/23/2013 12:56 PM, Michael Wild wrote: > > Yes, I thought of that too. While this "solves" this case (it certainly > is not very discoverable for future maintainers), it does not help in > the case of container support. Say I wanted to expose > std::vector (or std::vector from the Boost.Python > FAQ, for that matter) using the boost::python::vector_indexing_suite. I > am perfectly able to create such a list, I can append items, the only > thing I can't do is *retrieving* them. It's like a black hole for data ;-) > I'm afraid the vector_indexing_suite is some black magic I'm not terribly familiar with. But I do know that in some contexts it returns proxy objects in order to allow setting and safer lifetime management, and I suspect that's what is not playing nicely with your custom converters. Or have you investigated that further and determined that it's calling make_getter, and that's why you're focused on that? In any case, I think you may be able to pass a call policy to vector_indexing_suite, though I may be thinking of the v2 indexing suite that never got packaged with boost::python but is available as part of Roman's Py++. Jim From themiwi at users.sourceforge.net Wed Jan 23 19:08:32 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Wed, 23 Jan 2013 19:08:32 +0100 Subject: [C++-sig] to_python converter and make_getter In-Reply-To: <510025D9.60100@gmail.com> References: <50FF0227.7040802@users.sourceforge.net> <50FF1235.8050904@gmail.com> <50FF767E.6090403@users.sourceforge.net> <5100136C.4000802@gmail.com> <51002466.2030406@users.sourceforge.net> <510025D9.60100@gmail.com> Message-ID: <51002720.1060404@users.sourceforge.net> On 01/23/2013 07:03 PM, Jim Bosch wrote: > On 01/23/2013 12:56 PM, Michael Wild wrote: > > > >> >> Yes, I thought of that too. While this "solves" this case (it certainly >> is not very discoverable for future maintainers), it does not help in >> the case of container support. Say I wanted to expose >> std::vector (or std::vector from the Boost.Python >> FAQ, for that matter) using the boost::python::vector_indexing_suite. I >> am perfectly able to create such a list, I can append items, the only >> thing I can't do is *retrieving* them. It's like a black hole for data >> ;-) >> > > I'm afraid the vector_indexing_suite is some black magic I'm not > terribly familiar with. But I do know that in some contexts it returns > proxy objects in order to allow setting and safer lifetime management, > and I suspect that's what is not playing nicely with your custom > converters. Or have you investigated that further and determined that > it's calling make_getter, and that's why you're focused on that? Not at all, I just stumbled across this problem a little later than the one with the make_getter. Somehow I suspect that if I can teach bp to properly return by value, both cases would be resolved automagically. After all, things work smoothly for std::string. Michael From themiwi at users.sourceforge.net Fri Jan 25 06:18:24 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Fri, 25 Jan 2013 06:18:24 +0100 Subject: [C++-sig] to_python converter and make_getter In-Reply-To: <51002720.1060404@users.sourceforge.net> References: <50FF0227.7040802@users.sourceforge.net> <50FF1235.8050904@gmail.com> <50FF767E.6090403@users.sourceforge.net> <5100136C.4000802@gmail.com> <51002466.2030406@users.sourceforge.net> <510025D9.60100@gmail.com> <51002720.1060404@users.sourceforge.net> Message-ID: <510215A0.7080301@users.sourceforge.net> [re-post with the correct from-address, the original got rejected] On 01/23/2013 07:08 PM, Michael Wild wrote: > On 01/23/2013 07:03 PM, Jim Bosch wrote: >> On 01/23/2013 12:56 PM, Michael Wild wrote: >> >> >> >>> >>> Yes, I thought of that too. While this "solves" this case (it certainly >>> is not very discoverable for future maintainers), it does not help in >>> the case of container support. Say I wanted to expose >>> std::vector (or std::vector from the Boost.Python >>> FAQ, for that matter) using the boost::python::vector_indexing_suite. I >>> am perfectly able to create such a list, I can append items, the only >>> thing I can't do is *retrieving* them. It's like a black hole for data >>> ;-) >>> >> >> I'm afraid the vector_indexing_suite is some black magic I'm not >> terribly familiar with. But I do know that in some contexts it returns >> proxy objects in order to allow setting and safer lifetime management, >> and I suspect that's what is not playing nicely with your custom >> converters. Or have you investigated that further and determined that >> it's calling make_getter, and that's why you're focused on that? > > Not at all, I just stumbled across this problem a little later than the > one with the make_getter. Somehow I suspect that if I can teach bp to > properly return by value, both cases would be resolved automagically. > After all, things work smoothly for std::string. > > Michael > About the indexing_suite: By setting the NoProxy template argument to true, the custom string is being converted correctly, leaving me only with make_getter to be dealt with. For now I think I'll go with explicitly specializing make_getter. AFAIK this does no harm and automagically fixes class_::add_property() and friends. Thanks for all the input. Michael From liujz39 at gmail.com Fri Jan 25 11:57:52 2013 From: liujz39 at gmail.com (salinea) Date: Fri, 25 Jan 2013 02:57:52 -0800 (PST) Subject: [C++-sig] How to debug pyd File in Visual Studio??? Message-ID: <1359111472240-4641746.post@n4.nabble.com> Recently, I build a hybrid system with C++ and python. First,I encapsulate a class(I can't guarantee the robustness of this class ) with boost.python which can implement some functions that can not be implemented by C++, I get a .pyd File in result. Second,I embed a python interpreter in c++. Third, use the embed interpreter to execute a .py File.The .py File include the module that in .pyd File I created. Here, the problem comes out! When I start my main project. I can only debug the problems in my main project, when my main project use the python interpreter to execute the python interpreter, I can't see what happened in my pyd File, the whole project collapsed.I know the error is in the pyd File, and if I set a break point in my resource files of pyd File, either the project will go to the break point. Is there any methods to debug the resource file in this condition! -- View this message in context: http://boost.2283326.n4.nabble.com/How-to-debug-pyd-File-in-Visual-Studio-tp4641746.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From sybren at stuvel.eu Fri Jan 25 18:43:40 2013 From: sybren at stuvel.eu (=?UTF-8?Q?Sybren_A=2E_St=C3=BCvel?=) Date: Fri, 25 Jan 2013 18:43:40 +0100 Subject: [C++-sig] How to debug pyd File in Visual Studio??? In-Reply-To: <1359111472240-4641746.post@n4.nabble.com> References: <1359111472240-4641746.post@n4.nabble.com> Message-ID: Hi Salinea, You can attach the Visual Studio debugger to any running process, including Python. That way you can debug Python code from your Python IDE, and connect VS to debug your C++ at the same time. Best, Sybren On 25 January 2013 11:57, salinea wrote: > Recently, I build a hybrid system with C++ and python. > First,I encapsulate a class(I can't guarantee the robustness of this > class ) with boost.python which can implement some functions that can not > be > implemented by C++, I get a .pyd File in result. > Second,I embed a python interpreter in c++. > Third, use the embed interpreter to execute a .py File.The .py File > include the module that in .pyd File I created. > Here, the problem comes out! When I start my main project. I can only > debug the problems in my main project, when my main project use the python > interpreter to execute the python interpreter, I can't see what happened in > my pyd File, the whole project collapsed.I know the error is in the pyd > File, and if I set a break point in my resource files of pyd File, either > the project will go to the break point. > Is there any methods to debug the resource file in this condition! > > > > -- > View this message in context: > http://boost.2283326.n4.nabble.com/How-to-debug-pyd-File-in-Visual-Studio-tp4641746.html > Sent from the Python - c++-sig mailing list archive at Nabble.com. > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Sybren A. St?vel http://stuvel.eu/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From themiwi at users.sourceforge.net Sun Jan 27 11:02:05 2013 From: themiwi at users.sourceforge.net (Michael Wild) Date: Sun, 27 Jan 2013 11:02:05 +0100 Subject: [C++-sig] CallPolicy for operators Message-ID: <5104FB1D.3060506@users.sourceforge.net> Hi all Is there a way to apply a CallPolicy to operator definitions? In particular, I'm interested in the inplace operators (+=, -=, *=, /= and friends). To give a bit more context: The library I'm trying to wrap exposes some static const objects. So far, I have been able to wrap modifying function by having a registration facility for these static const objects and a custom CallPolicy that raises an AttributError when one tries to modify one of the registered objects. One option I see is to directly define __iadd__ etc. instead of using the built-in convenience operators. However, I'm not sure whether that has unintended side-effects. I haven't completely understood the operators implementation in bp, but it looks fairly involved. Thanks Michael From fred.baba at gmail.com Wed Jan 30 04:33:00 2013 From: fred.baba at gmail.com (Fred Baba) Date: Tue, 29 Jan 2013 21:33:00 -0600 Subject: [C++-sig] Segfault when accessing a boost::python::dict? Message-ID: Hello, I'm a bit new to boost::python and I've run into a strange segmentation fault issue. I'm attempting to convert a dict object to a boost::property_tree::ptree using the code below. I'm getting the error when I attempt to access the input dict, with the following stacktrace: (gdb) bt #0 0x00000001004d58df in PyObject_RichCompare () #1 0x00000001004d64e0 in PyObject_RichCompareBool () #2 0x00000001004cbf9d in lookdict () #3 0x00000001004cfa4f in dict_subscript () #4 0x00000001000c9cc5 in boost::python::api::getitem () #5 0x000000010000218b in boost::python::api::const_item_policies::get (target=@0x7fff5fbff680, key=@0x7fff5fbff688) at object_items.hpp:68 #6 0x000000010000371b in boost::python::api::proxy::operator boost::python::api::object (this=0x7fff5fbff680) at proxy.hpp:64 #7 0x0000000100000f56 in ptree_from_dict (d=@0x7fff5fbff6d0) at test_ptree.cpp:55 #8 0x00000001000015fd in main () at test_ptree.cpp:104 Any help/advice would be greatly appreciated. The code below was adapted from an existing github project, and I can't figure out what's amiss. Thanks, Fred Baba template bool try_set(boost::property_tree::ptree &pt, const std::string &key, object &val) { extract ex(val); if (ex.check()) { pt.put(key, ex()); return true; } return false; } boost::property_tree::ptree ptree_from_dict(const dict &d) { boost::property_tree::ptree pt; boost::python::list keys = d.keys(); for (int i = 0; i < len(keys); ++i) { std::string key = extract(keys[i]); object val = d[key]; try_set(pt, key, val) || try_set(pt, key, val) || try_set(pt, key, val); } return pt; } int main() { try { Py_Initialize(); dict d; d["foo"] = 5; d["bar"] = "baz"; object o = ptree_to_object(ptree()); ptree p = ptree_from_dict(d); write_json(std::cout, p); Py_Finalize(); } catch (error_already_set const&) { PyErr_Print(); } return 0; }