Python newbie trying to embed in C++
Hello all, I'm new to Python and just starting to learn it. For he needs of my project, I need to call some specific methods in Python scripts from C++. For now, I just compiled the example in the Python documentation about Pure Embedding to try it out ( http://docs.python.org/2/extending/embedding.html#pure-embedding ). I'm trying to test it on an extremely simple script called test.py which contains the following: def testPY( value ): print('You input ', value ) def Hello(): print('Hello') When I run the generated exe, I get errors about the functions not existing... TestPython.exe test Hello AttributeError: 'module' object has no attribute 'Hello' Cannot find function "Hello" My Python version is 2.7.3 because that's the version used in the module we need to access. And I'm using VS2010 SP1 for compiling my C++ because that's the version used to generate our DLLs and EXEs. Could anyone tell me why this is happening? And I'd appreciate it if you could give me pointers to how to easily call Python from C++. Thanks in advance for your help, Marwan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python newbie trying to embed in C++
On 27/02/2013 10:26, Ian Kelly wrote: On Wed, Feb 27, 2013 at 1:51 AM, Marwan wrote: When I run the generated exe, I get errors about the functions not existing... TestPython.exe test Hello AttributeError: 'module' object has no attribute 'Hello' Cannot find function "Hello" "test" is the name of a module in the standard library. My guess would be that for some reason it's importing that module rather than your test.py. Make sure that test.py can be found on your sys.path, and perhaps change the name of your module to reduce confusion. I just noticed that my reply went to the message sender and not to the newsgroup, so I'm posting again: thanks, that was it. Just renaming my test.py file solved the problem. %M -- http://mail.python.org/mailman/listinfo/python-list
Re: Python newbie trying to embed in C++
On 27/02/2013 16:17, Christian Gollwitzer wrote: Am 27.02.13 09:51, schrieb Marwan: And I'd appreciate it if you could give me pointers to how to easily call Python from C++. Maybe you can use boost::python? http://www.boost.org/doc/libs/1_53_0/libs/python/doc/ Cave: I haven't used it and don't know if it is up-to-date. Christian I just noticed that my reply went to the message sender and not to the newsgroup, so I'm posting again: thanks, I'll look into that. %M -- http://mail.python.org/mailman/listinfo/python-list