Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'attribute': 0.05; 'compiler': 0.05; 'suppose': 0.07; 'scripts': 0.09; 'python': 0.09; '*is*': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:trying': 0.09; 'terry': 0.09; 'def': 0.10; '2.7': 0.13; '2.7.3': 0.16; '3:51': 0.16; 'c++.': 0.16; 'compilers': 0.16; 'dlls': 0.16; 'mismatch': 0.16; 'presume': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'regenerate': 0.16; 'subject:embed': 0.16; 'vs2010': 0.16; 'worst': 0.16; 'later': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'tests': 0.18; 'input': 0.18; '(or': 0.18; 'windows': 0.19; 'module': 0.19; 'all,': 0.21; 'trying': 0.21; 'do.': 0.21; 'not,': 0.21; 'embedding': 0.22; 'work,': 0.22; 'example': 0.23; 'work.': 0.23; 'errors': 0.23; 'project,': 0.24; 'second': 0.24; 'script': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'am,': 0.27; 'compiled': 0.27; 'done.': 0.27; 'possibly': 0.27; 'c++': 0.27; 'header:X-Complaints-To:1': 0.28; 'decide': 0.28; 'initial': 0.28; 'run': 0.28; "i'm": 0.29; 'maybe': 0.29; 'function': 0.30; 'url:python': 0.32; 'file': 0.32; 'not.': 0.32; 'running': 0.32; 'extract': 0.33; 'to:addr:python- list': 0.33; 'that,': 0.34; 'version': 0.34; 'project': 0.34; 'needed': 0.35; 'problem,': 0.35; 'there': 0.35; 'received:org': 0.36; 'really': 0.36; '2010.': 0.36; 'url:org': 0.36; 'test': 0.36; 'too': 0.36; 'author': 0.37; 'python.org': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'url:docs': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'your': 0.60; 'real': 0.61; 'our': 0.65; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Python newbie trying to embed in C++ Date: Wed, 27 Feb 2013 16:17:58 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361999903 news.xs4all.nl 6976 [2001:888:2000:d::a6]:55854 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40072 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