Python in C integration and WxPython

Discussion in 'Python' started by Alain Paschoud, Sep 15, 2005.

  1. Hi all,

    I made a small dialog in WxPython. I can run the python script with a
    double-click or through command line, and everything goes fine (dialog
    appears, which means that wx module has been found).
    Then, I decided to write a C program (under Windows, with Cygwin) that
    will read my script (through PyRun_SimpleFile() function) and run it.
    But the system doesn't find the wx module to import...

    Traceback (most recent call last):
    File "Dialog.py", line 2, in ?
    import wx
    ImportError: No module named wx

    How can I say to my program where to search for this module ? I tried to
    set $PYTHONPATH and $PYTHONHOME, but this doesn't change anything.

    More generally : Does a C program that embedded python run an external
    executable (interpreter), or does it only load libraries ?

    Thank you very much for any help on this topic.

    Best regards.
     
    Alain Paschoud, Sep 15, 2005
    #1
    1. Advertising

  2. Alain Paschoud

    David Wilson Guest

    It sounds like your C program and Python script are running under
    different interpreters. Your C program almost certainly is using a
    Python version that comes with Cygwin, while the script is probably
    using a native win32 Python that has wxPython installed.

    Assuming this is true, then compiling your C program natively on
    Windows should solve the problem. Alternatively, if wxPython is
    available for cygwin (possibly via cygwin's X server) then installing
    it would also help.


    David.


    Alain Paschoud wrote:
    > Hi all,
    >
    > I made a small dialog in WxPython. I can run the python script with a
    > double-click or through command line, and everything goes fine (dialog
    > appears, which means that wx module has been found).
    > Then, I decided to write a C program (under Windows, with Cygwin) that
    > will read my script (through PyRun_SimpleFile() function) and run it.
    > But the system doesn't find the wx module to import...
    >
    > Traceback (most recent call last):
    > File "Dialog.py", line 2, in ?
    > import wx
    > ImportError: No module named wx
    >
    > How can I say to my program where to search for this module ? I tried to
    > set $PYTHONPATH and $PYTHONHOME, but this doesn't change anything.
    >
    > More generally : Does a C program that embedded python run an external
    > executable (interpreter), or does it only load libraries ?
    >
    > Thank you very much for any help on this topic.
    >
    > Best regards.
     
    David Wilson, Sep 15, 2005
    #2
    1. Advertising

  3. Hi David,

    Thanks for your answer, but I don't think the problem comes from which
    Python version I use. I installed the Python from cygwin, but this
    didn't change everything.

    Finally, I fullfill the PYTHONPATH environment variable to make the
    system finding the wx module. It is now able to find it. But after that,
    the mode _core is called, and finally, the module _core_, which is not
    found. The only _core_ file that I have is the "_core_.pyd" which is in
    the wx directory. Of course, I added this directory path to PYTHONPATH,
    but without any success.... is it because this is a .pyd file ?

    Here are the logs I get:

    Traceback (most recent call last):
    File "Dialog.py", line 2, in ?
    import wx
    File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\__init__.py",
    line 42, in ?
    from wx._core import *
    File
    "/cygdrive/c/Python24/Lib/site-packages/wx-2.6-msw-ansi/wx/_core.py",
    line 4, in ?
    import _core_

    Here is the result of the Py_GetPath() function:

    /cygdrive/c/Python24/Lib/site-packages/:/cygdrive/c/Python24/Lib/site-packages
    /wx-2.6-msw-ansi/:/cygdrive/c/Python24/Lib/site-packages/wx-2.6-msw-ansi/wxPython:/cygdriv
    e/c/Python24/Lib/site-packages/wx-2.6-msw-ansi/wx:.:/usr/bin/lib/python24.zip:/usr/bin/lib
    /python2.4/:/usr/bin/lib/python2.4/plat-cygwin:/usr/bin/lib/python2.4/lib-tk:/usr/bin/lib/
    python2.4/lib-dynload

    Any hints ??

    Thanks.

    N.B: Same problem when I run the script directly with "python -v Dialog.py".

    David Wilson wrote:
    > It sounds like your C program and Python script are running under
    > different interpreters. Your C program almost certainly is using a
    > Python version that comes with Cygwin, while the script is probably
    > using a native win32 Python that has wxPython installed.
    >
    > Assuming this is true, then compiling your C program natively on
    > Windows should solve the problem. Alternatively, if wxPython is
    > available for cygwin (possibly via cygwin's X server) then installing
    > it would also help.
    >
    >
    > David.
    >
    >
    > Alain Paschoud wrote:
    >
    >>Hi all,
    >>
    >>I made a small dialog in WxPython. I can run the python script with a
    >>double-click or through command line, and everything goes fine (dialog
    >>appears, which means that wx module has been found).
    >>Then, I decided to write a C program (under Windows, with Cygwin) that
    >>will read my script (through PyRun_SimpleFile() function) and run it.
    >>But the system doesn't find the wx module to import...
    >>
    >>Traceback (most recent call last):
    >> File "Dialog.py", line 2, in ?
    >> import wx
    >>ImportError: No module named wx
    >>
    >>How can I say to my program where to search for this module ? I tried to
    >>set $PYTHONPATH and $PYTHONHOME, but this doesn't change anything.
    >>
    >>More generally : Does a C program that embedded python run an external
    >>executable (interpreter), or does it only load libraries ?
    >>
    >>Thank you very much for any help on this topic.
    >>
    >>Best regards.

    >
    >
     
    Alain Paschoud, Sep 15, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anand
    Replies:
    1
    Views:
    357
    Cliff Wells
    Jul 23, 2003
  2. ulysses
    Replies:
    4
    Views:
    777
    Werner Schiendl
    Oct 22, 2003
  3. Logan
    Replies:
    5
    Views:
    766
    David Bolen
    Dec 11, 2003
  4. Ruben Charles
    Replies:
    6
    Views:
    503
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Oct 25, 2005
  5. Robin Dunn
    Replies:
    0
    Views:
    527
    Robin Dunn
    Mar 28, 2006
Loading...

Share This Page