Help: Basic window crashes Python on Windows Vista

I’ve just started working with wxPython, using both the book and the
website, and I’m getting some crashes with really basic code. I’ve
given details below; please let me know if there’s any other info
that’s relevant.

Thanks in advance for your help!

–Mike

Problem description: Python crashes when showing a simple window

Steps to reproduce: enter the code below either in the interpreter or
in a file and run it:

import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, wx.ID_ANY, “Hello World”)
frame.Show(True)
app.MainLoop()

(Taken from http://wiki.wxpython.org/Getting%20Started#head-6e8427493dcc765fb873a1838adfbd6b8d08e0ee)

The crash happens when the wxPython window is given focus, bringing
down python.exe. It can also happen without the last call, during
frame.Show(), if the window is moved or its shape is changed.

Sometimes this will run okay the first time through in PythonWin.
However trying to run it again (even after closing the script file and
reopening it) gives the following error before eventually crashing
PythonWin:

Traceback (most recent call last):
File "C:\Python26\Lib\SITE-P~1\

PYTHON~1\pywin\framework\scriptutils.py",

line 312, in RunScript

exec codeObject in __main__.__dict__

File “C:\Users\Mike\Documents\Programming\wxPython\test.py”, line 3,

in

frame = wx.Frame(None, wx.ID_ANY, "Hello World")

File “C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx_windows.py”,

line 505, in init

_windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))

PyNoAppError: The wx.App object must be created first!

Environment

···

OS: Vista Home Premium, with all updates

Python distribution: ActiveState Python 2.6.1.1 (Python 2.6.1)

wxPython version: 2.8.9.2 for Python 2.6, from win32-unicode binary

from http://www.wxpython.org/download.php

wxPython installation directory: C:\Python26\Lib\site-packages (default)

PYTHONPATH: C:\Python26;C:\Python26\Lib;C:\Python26\Lib\site-packages;C:\Python26\Lib\site-packages\django;C:\Python26\Lib\site-packages\django\bin;C:\Python26\Lib\site-packages\django*

(My PYTHONPATH has all this extra stuff because pointing it to the site-packages directory wasn’t sufficient for running django, for some reason.)

Hello,

···

2009/3/16 Mike Dartt mikedartt@gmail.com

I’ve just started working with wxPython, using both the book and the
website, and I’m getting some crashes with really basic code. I’ve

given details below; please let me know if there’s any other info
that’s relevant.

Thanks in advance for your help!
To put it short there are issues with python2.6/wxpython on Vista right now, so use Python 2.5 instead.

If your interested in more details search the list archives for other discussions on this topic.

Cody

Sometimes this will run okay the first time through in PythonWin.

However trying to run it again (even after closing the script file and

reopening it) gives the following error before eventually crashing

PythonWin:

Traceback (most recent call last):

File “C:\Python26\Lib\SITE-P~1
PYTHON~1\pywin\framework\scriptutils.py”,

line 312, in RunScript

exec codeObject in __main__.__dict__

File “C:\Users\Mike\Documents\Programming\wxPython\test.py”, line 3,

in

frame = wx.Frame(None, wx.ID_ANY, "Hello World")

File “C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx_windows.py”,

line 505, in init

_windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))

PyNoAppError: The wx.App object must be created first!

The same thing happened to me when using Idle and it was not operational system/python version related. The solution is deleting the app when the program quits.

It usually goes along this lines:

if name==“main”:
try:
app = wx.App()
frame = MyCustomFrame(None, -1)
app.MainLoop()
finally:
del app

On windows xp, python version 2.6 it allowed me to run the same program as many times I wished in Idle without PyNoAppError appearing.

Thanks, Cody and Lucas. Unfortunately, I've had essentially the same
problem after uninstalling all my Python-related programs, clearing my
PYTHONPATH, reinstalling ActivePython 2.5 and wxPython 2.8.9.2 for
Python 2.5, and adding the try/finally block.

The main differences are:
1) Instead of getting the PyNoAppError on the 2nd run, the window
loads and then crashes python
2) The error message I get is a Visual C++ error message, not the
standard Windows "Python.exe has quit unexpectedly" error

At this point I'm thinking that maybe it's the ActivePython
installation that's at fault and maybe I should just get the standard
CPython download from python.org. Or maybe I shouldn't compile the
.py files to .pyc files during the wxPython install.

That, or I should develop on Linux, where most of this would be
pre-packaged in a distro, but since Windows is my main target
platform, I want to get this working. :slight_smile:

Thanks again,

Mike

···

2009/3/16 Lucas Boppre Niehues <lucasboppre@gmail.com>:

Sometimes this will run okay the first time through in PythonWin.
However trying to run it again (even after closing the script file and
reopening it) gives the following error before eventually crashing
PythonWin:

Traceback (most recent call last):
File "C:\Python26\Lib\SITE-P~1\
PYTHON~1\pywin\framework\scriptutils.py",
line 312, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Mike\Documents\Programming\wxPython\test.py", line 3,
in <module>
frame = wx.Frame(None, wx.ID_ANY, "Hello World")
File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py",
line 505, in __init__
_windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))
PyNoAppError: The wx.App object must be created first!

The same thing happened to me when using Idle and it was not operational
system/python version related. The solution is deleting the app when the
program quits.

It usually goes along this lines:

if __name__=="__main__":
try:
app = wx.App()
frame = MyCustomFrame(None, -1)
app.MainLoop()
finally:
del app

On windows xp, python version 2.6 it allowed me to run the same program as
many times I wished in Idle without PyNoAppError appearing.

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

  1. Instead of getting the PyNoAppError on the 2nd run, the window

loads and then crashes python
Did you try deleting the app when the program ends? If the error is in the second run, something from the first one must be still alive.
And I’ve seens the Visual C++ error messages in quite random times, like when using Flash or Corel Draw, so I guess it doesn’t mean much.

That, or I should develop on Linux, where most of this would be

pre-packaged in a distro, but since Windows is my main target

platform, I want to get this working. :slight_smile:
Don’ count on that. I using linux. It took a long time to build the new version when it came out (slow distro repository update), and I’m still not able to install it with MediaCtrl enabled.

(Executive summary: The PythonWin IDE chokes on wxPython 2.8.9.2, but
IDLE doesn't.)

Hi, everyone--

After a variety of testing, with uninstalls and reinstalls between, it
looks like this is something that's the matter with the PythonWin IDE.
(I've detailed my last testing procedure below in case anyone is
yearning for particulars. :slight_smile:

I have yet to reinstall my Django package, but I feel comfortable at
this point saying that the PythonWin IDE (both v. 2.5 & 2.6) has
problems with wxPython 2.8.9.2, even when the App object is explicitly
destroyed at the end of the script. (While my notes below only talk
about PythonWin 2.6, I was seeing the same problem with my attempts to
use 2.5 earlier today.)

Fortunately, it looks like IDLE doesn't have these problems, so I can
at least continue learning wxPython and still use a decent IDE.
Interestingly, the interpreter in IDLE output the following string
when starting either of the scripts: "=====RESTART===="; neither
PythonWin nor the command line Python did this.

I suppose the next step would be to test PythonWin with the last
stable release of wxPython (2.6.4.0) to see if something in wxPython
changed between releases, but I'm excited to actually do some
programming now that I have things working, so it might be a while
before I get around to that. :slight_smile:

Thanks again for the suggestions!

--Mike

Testing procedure:
1) Clear all the Python stuff off my computer (uninstall, delete, etc.)
2) Restart to clear the PATH environment variable
3) Install the following:
    a. Python for Windows 2.6.1 binary from python.org, full install
    b. pywin32-213 package for Python 2.6
    c. wxPython 2.8.9.2 w/Unicode package for Python 2.6, compiling
pyc files and making batch files after install
4) Make a copy of python.exe and use it to run the update_manifest.py
file from wxPython
5) Run the offending scripts several times (the one detailed below and
"bare.py" from section 1.2 in "wxPython in Action") from IDLE, via F5
or the "Run -> Run Module" menu command
    --> PASS
6) Install the following, rerunning the tests on each script between
each install:
    a. PIL 1.1.6
    b. cx_Oracle 5.0.1 driver for Oracle 10g
    --> PASSed both times
7) Restart
8) Run tests again in IDLE
    --> PASS
9) Run script below in PythonWin IDE via either the "Run" toolbar
button or the "File -> Run" menu command--just close the window after
it appears via the "X" button in the upper right-hand corner.
    * No arguments passed to script, no debugging
10) Click on "Open File" button or "File -> Open" menu item
    --> CRASH after file dialog box opens, with Windows Vista standard
"Pythonwin.exe has stopped working" dialog box

The crash occurs after running the script just once, for what it's worth.

···

2009/3/16 Lucas Boppre Niehues <lucasboppre@gmail.com>:

1) Instead of getting the PyNoAppError on the 2nd run, the window
loads and then crashes python

Did you try deleting the app when the program ends? If the error is in the
second run, something from the first one must be still alive.
And I've seens the Visual C++ error messages in quite random times, like
when using Flash or Corel Draw, so I guess it doesn't mean much.

That, or I should develop on Linux, where most of this would be
pre-packaged in a distro, but since Windows is my main target
platform, I want to get this working. :slight_smile:

Don' count on that. I using linux. It took a long time to build the new
version when it came out (slow distro repository update), and I'm still not
able to install it with MediaCtrl enabled.

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Mike Dartt wrote:

(Executive summary: The PythonWin IDE chokes on wxPython 2.8.9.2, but
IDLE doesn't.)

I don't know that PythonWin ever worked right with wxPython -- the mainloops get tangled up, 'cause pythonWin runs your code inside the same python process as the IDE -- just a plain bad idea, really, though easy to impliment.

Has PythonWin been updated in years? I thought it was pretty dead.

PythonWin IDE (both v. 2.5 & 2.6) has
problems with wxPython 2.8.9.2, even when the App object is explicitly
destroyed at the end of the script.

wx doesn't take well to stopping and re-starting an App -- you really can have only one wxApp per run.

Fortunately, it looks like IDLE doesn't have these problems,

I think IDLE ws re-factored a few years back to run code in a separate process.

at least continue learning wxPython and still use a decent IDE.

You can use PythonWin, you just can't run the code from it. There are also many other options -- google away, but be sure to look at:

BoaConstructor
SPE
Editra
WindIDE
...

If you really want a debugger, WinPDB is nice.

Interestingly, the interpreter in IDLE output the following string
when starting either of the scripts: "=====RESTART====";

That may be IDLE's indication that it is starting a new python process -- which you really need to do to run wxPython.

I suppose the next step would be to test PythonWin with the last
stable release of wxPython (2.6.4.0)

don't bother.

Welcome to wxPython -- sorry for the slow start!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Lucas Boppre Niehues wrote:

    Sometimes this will run okay the first time through in PythonWin.
    However trying to run it again (even after closing the script file and
    reopening it) gives the following error before eventually crashing
    PythonWin:

Don't run wxPython apps in anything that runs your code in the same process as the editor/IDE.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Mike Dartt wrote:

I've just started working with wxPython, using both the book and the
website, and I'm getting some crashes with really basic code. I've
given details below; please let me know if there's any other info
that's relevant.

Thanks in advance for your help!

--Mike

Problem description: Python crashes when showing a simple window

Steps to reproduce: enter the code below either in the interpreter or
in a file and run it:

import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, wx.ID_ANY, "Hello World")
frame.Show(True)
app.MainLoop()

(Taken from Getting Started - wxPyWiki)

The crash happens when the wxPython window is given focus, bringing
down python.exe. It can also happen without the last call, during
frame.Show(), if the window is moved or its shape is changed.

Sometimes this will run okay the first time through in PythonWin.
However trying to run it again (even after closing the script file and
reopening it) gives the following error before eventually crashing
PythonWin:

Traceback (most recent call last):
File "C:\Python26\Lib\SITE-P~1\
PYTHON~1\pywin\framework\scriptutils.py",
line 312, in RunScript
   exec codeObject in __main__.__dict__
File "C:\Users\Mike\Documents\Programming\wxPython\test.py", line 3,
in <module>
   frame = wx.Frame(None, wx.ID_ANY, "Hello World")
File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py",
line 505, in __init__
   _windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))
PyNoAppError: The wx.App object must be created first!

Environment
------------------
OS: Vista Home Premium, with all updates

Python distribution: ActiveState Python 2.6.1.1 (Python 2.6.1)

wxPython version: 2.8.9.2 for Python 2.6, from win32-unicode binary
from Redirecting...

wxPython installation directory: C:\Python26\Lib\site-packages (default)

PYTHONPATH: C:\Python26\;C:\Python26\Lib\;C:\Python26\Lib\site-packages\;C:\Python26\Lib\site-packages\django\;C:\Python26\Lib\site-packages\django\bin\;C:\Python26\Lib\site-packages\django\*

(My PYTHONPATH has all this extra stuff because pointing it to the site-packages directory wasn't sufficient for running django, for some reason.)

Just an FYI that IDLE will sometimes give a similar message with wx programs. I can usually get it to work, but when I can't, I just run the program from the command line. I also use Wingware's Wing IDE and it works pretty well with wxPython programs too.

There were some screwy issues with Python 2.6, but it seemed to be more related to building binaries with py2exe than just running the scripts (as far as I know). I think 2.5 is fine for now though. The 3rd party packages aren't all up to 2.6 yet anyway.

I'm not sure what Lucas is talking about. I can install the newest wxPython on the day it comes out on Ubuntu with near zero issues. Some of the more obscure distros are going to be different. I think most major distros get their repositories updated within a week of the release though.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org