Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40039 > unrolled thread
| Started by | Marwan <LarrxX@free.fr> |
|---|---|
| First post | 2013-02-27 09:51 +0100 |
| Last post | 2013-02-27 16:17 -0500 |
| Articles | 8 — 7 participants |
Back to article view | Back to comp.lang.python
Python newbie trying to embed in C++ Marwan <LarrxX@free.fr> - 2013-02-27 09:51 +0100
Re: Python newbie trying to embed in C++ Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-27 02:26 -0700
Re: Python newbie trying to embed in C++ Marwan Badawi <Marwan.Badawi@inria.fr> - 2013-02-28 09:11 +0100
Re: Python newbie trying to embed in C++ Christian Gollwitzer <auriocus@gmx.de> - 2013-02-27 16:17 +0100
Re: Python newbie trying to embed in C++ Marwan Badawi <Marwan.Badawi@inria.fr> - 2013-02-28 09:28 +0100
Re: Python newbie trying to embed in C++ Gisle Vanem <gvanem@broadpark.no> - 2013-02-28 11:47 +0100
Re: Python newbie trying to embed in C++ Michael Torrie <torriem@gmail.com> - 2013-02-28 11:12 -0700
Re: Python newbie trying to embed in C++ Terry Reedy <tjreedy@udel.edu> - 2013-02-27 16:17 -0500
| From | Marwan <LarrxX@free.fr> |
|---|---|
| Date | 2013-02-27 09:51 +0100 |
| Subject | Python newbie trying to embed in C++ |
| Message-ID | <kgkhdu$fjh$1@news-v3.irisa.fr> |
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
[toc] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-02-27 02:26 -0700 |
| Message-ID | <mailman.2598.1361957234.2939.python-list@python.org> |
| In reply to | #40039 |
On Wed, Feb 27, 2013 at 1:51 AM, Marwan <LarrxX@free.fr> 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.
[toc] | [prev] | [next] | [standalone]
| From | Marwan Badawi <Marwan.Badawi@inria.fr> |
|---|---|
| Date | 2013-02-28 09:11 +0100 |
| Message-ID | <kgn3gc$pb2$1@news-v3.irisa.fr> |
| In reply to | #40041 |
On 27/02/2013 10:26, Ian Kelly wrote: > On Wed, Feb 27, 2013 at 1:51 AM, Marwan <LarrxX@free.fr> 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
[toc] | [prev] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2013-02-27 16:17 +0100 |
| Message-ID | <kgl7v2$ot4$1@dont-email.me> |
| In reply to | #40039 |
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
[toc] | [prev] | [next] | [standalone]
| From | Marwan Badawi <Marwan.Badawi@inria.fr> |
|---|---|
| Date | 2013-02-28 09:28 +0100 |
| Message-ID | <kgn4fr$pb2$2@news-v3.irisa.fr> |
| In reply to | #40067 |
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
[toc] | [prev] | [next] | [standalone]
| From | Gisle Vanem <gvanem@broadpark.no> |
|---|---|
| Date | 2013-02-28 11:47 +0100 |
| Message-ID | <mailman.2645.1362048451.2939.python-list@python.org> |
| In reply to | #40124 |
"Marwan Badawi" <Marwan.Badawi@inria.fr> wrote: > 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. Yes, I often do that too; i.e. I'm subscribed to python-list@python.org and get all messages from comp.lang.python mirrored to the ML a bit later. I prefer the mailing-list over comp.lang.python since my NNTP server (eternal-september.org) is rather slow and my ISP has deprecated NNTP long time ago. I saw you uses Thunderbird on Windows. I'm not sure how it by default handles a reply-to when there is no "Reply-to" field in the header. To the address in "From" / "Sender" or what? I wish the NNTP-mailing list gateway could add a "Reply-to: <python-list@python.org>". Since I'm getting the messages via the ML, I think it would be logical that the replies should by default go to the ML too. --gv
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-02-28 11:12 -0700 |
| Message-ID | <mailman.2661.1362075173.2939.python-list@python.org> |
| In reply to | #40124 |
On 02/28/2013 03:47 AM, Gisle Vanem wrote: > I saw you uses Thunderbird on Windows. I'm not sure how it by default handles > a reply-to when there is no "Reply-to" field in the header. To the address in > "From" / "Sender" or what? Thunderbird has a handy, "reply to list" button that works every time no matter what the rely-to field is set to.
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-02-27 16:17 -0500 |
| Message-ID | <mailman.2626.1361999903.2939.python-list@python.org> |
| In reply to | #40039 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web