Search code examples
wxpython

Import PyDeadObjectError with wx version 3.0.3


Using wxPython 3.0.3 I am unable to import PyDeadObjectError. I believe when I had 3.0 installed, this was not a problem. I'm getting a "cannot import name" error.

BsMBP:tests bem$ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
>>> import wx
>>> wx.version()
'3.0.3.dev1836+f764b32 osx-cocoa (phoenix)'
>>> 
>>> import PyDeadObjectError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PyDeadObjectError
>>> 
>>> from wx._core import PyDeadObjectError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name PyDeadObjectError
>>> 
>>> exit()

How can I resolve this error?


Solution

  • As mentioned in the Migration Guide (at http://wxpython.org/Phoenix/docs/html/MigrationGuide.html#wx-pydeadobjecterror-runtimeerror) the ugly hack that generated that exception is no longer needed, so the exception class has been removed. Now if you try to access a proxy object for a deleted C++ object a RuntimeError is raised instead. Or you can test the window in an if statement if you are expecting that it may have been deleted and avoid getting the exception at all.