0

I’m a newbie with python and just starting with wxPython.

I have some basic beginner code using wxPthon which runs fine in any other directory but the Aptana Workspace directory (or its subdirectories). Copy and paste the file – double-click on the file name with the mouse and it runs – but ONLY if the file is not in the Aptana workspace directory.(It makes no difference if Aptana is running or not) What is going on?

#!/usr/bin/python
# simple.py

import wx

app = wx.App()

frame = wx.Frame(None, -1, 'simple.py')
frame.Show()

app.MainLoop()

A probably related problem is that with wxPython in PyDev I’m getting similar errors to some other users – "Undefined variable from import:App" (or anything else with a wx.prefix.)

I’ve tried all the suggestions in Undefined variable from import when using wxPython in pydev eg reinstalling the python interpreter into PyDev, checking that wx-2.8-msw-unicode is correctly indicated on the System PYTHONPATH, ensuring that wxPython is included in the forced builtins. I've also done a few restarts, just in case...

I've also tried a couple of suggested hacks - Ctrl+1 comments on the error lines, even wx=wx (both remove the red error icons but the program still doesn't run .... “AttributeError: 'module' object has no attribute 'App'” when I try to run the program from Aptana)

Since the file runs OK outside the Aptana Workspace, there's obviously something about the Aptana Workspace that I don't understand. Has anyone got any suggestions?

Windows Vista Python 2.7 Aptana Studio 3

Community
  • 1
  • 1
Marg
  • 183
  • 1
  • 1
  • 6

1 Answers1

1

I checked it here inside of Aptana/PyDev and the code does work properly for me... (and imports are properly resolved without any red error icons).

So, the things to check would be:

  1. Remove all your .pyc files (right click project > pydev > remove .pyc files) -- it could be that you have some stale .pyc file there.

  2. Check your PYTHONPATH at runtime:

    import sys; print('\n'.join(sorted(sys.path)))

    and compare it with the one you have from the shell -- update your interpreter configuration inside PyDev if it's different.

  3. If you are able to import wx in your program, do the following:

    import wx; print(wx)

    and see if there's a difference between the one in the shell to the one within Eclipse.

If you're not able to make it work with that, please post the results you get from the items 2/3 both from Eclipse and the shell and paste the actual traceback you're getting when running the module.

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • Some nice suggestions for tracking down the problem there. I was inspired to revisit pydev continue trying to work with wxpython.... and the little red error icons have all disappeared without any help from me. The program now runs fine so the problem seems to have fixed itself - maybe I did a magic number of reboots since the problem occurred ???? I'll certainly keep the suggestions in mind if the problem recurs. Thanks for the assistance. – Marg Apr 16 '12 at 03:25