Python newbie trying to embed in C++
Terry Reedy
tjreedy at udel.edu
Wed Feb 27 16:17:58 EST 2013
On 2/27/2013 3:51 AM, Marwan wrote:
> 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')
I hope that the second def is not really indented in your original ;-).
> 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
The windows 2.7 on python.org is compiled with VS2008.
> 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.
Mixing VS compilers can be a problem, though I don't know if that is the
case here. Even if not, it might be for your real application.
You can try compiling 2.7.3 (or later from repository) with vs2010. I
know people have tried it. I presume it has been done. I don't know if
there is an (unofficial) vs2010 project file in the repository.
Python.org 3.3 *is* compiled with 2010. You can also try running the
module with that, possibly with the help of 2to3. It might not take too
work. The author of the module might be interested in a port anyway,
though maybe not. Or maybe extract just the part of the module you need
for conversion.
You might start with 3.3 for your tests and initial learning to make
sure that compiler mismatch is not a factor. When you get that to work,
then decide what to do.
I suppose the worst alternative might be to regenerate all the needed
dlls and exes with 2008.
--
Terry Jan Reedy
More information about the Python-list
mailing list