3

Attempting to run runsnake gives

ImportError: No module named wx 

Opening an ipython or python session seems to work fine:

>>> import wx
>>> import sys
>>> print [p for p in sys.path if 'wx' in p]    
['/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages', '/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa', '/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.1-osx_cocoa/tools']

as does putting that code in a script and calling python script.py. But putting that code at the beginning of runsnake.py prints an empty list (printing the whole sys.path prints a path quite different from my $PYTHONPATH).

Why would it be different, and how to I get it to recognize wxPython?

Edit: pip freeze output contains

SquareMap==1.0.1
RunSnakeRun==2.0.2b1
wxPython==2.9.4.0
wxPython-common==2.9.4.0
beardc
  • 20,283
  • 17
  • 76
  • 94
  • Can you please detail _how_ you installed runsnake? – dnozay Oct 21 '12 at 16:57
  • do you mean `pip freeze` shows both `RunSnakeRun` and `wxPython==2.9.4.0` and `wxPython-common==2.9.4.0`? – dnozay Oct 21 '12 at 17:03
  • I kind of fixed it by manually running `sys.path.extend(['wx directories...'])`. That got rid of the `import wx` problem, now I have what looks like an unrelated error along the lines of "Please run with a Framework build of python...". – beardc Oct 21 '12 at 17:04
  • what is sys.executable in/outside runsnake? – jfs Oct 21 '12 at 17:36
  • /usr/local/Cellar/python/2.7.3/bin/python in both cases (homebrew python) – beardc Oct 21 '12 at 17:51
  • note: PYTHONPATH environment variable adds directories to sys.path e.g., mine is unset as a rule. Are there `-S` option in the runsnake shebang? What sys.path looks like in `/usr/local/Cellar/.../python -c 'import sys; print sys.path'`? – jfs Oct 21 '12 at 18:29
  • The top line of the file was `#! /usr/bin/env python`, so no `-S` option. And when I do the `/usr/...' command you suggested, it includes the wx directories. – beardc Oct 21 '12 at 20:00

2 Answers2

1
  • Are you running runsnake.py and the python interpreter in the same virtualenv? If not you will not have the same packages.
  • If you are running runsnake.py in a virtual environment constructed with --no-site-packages, you will not have access to system-wide packages. Running pip freeze will tell you if you have access to wxPython. If you don't then that's the issue. You can create a new virtualenv properly.
  • Did you install wxPython before or after you run the virtualenv command?
  • Check the shebang, to see if it is running the same python #!/usr/bin/python or #!/usr/bin/env python
  • you can also try to force which interpreter to use with python runsnake.py

For Framework build of python on OSX, please see this question.

Community
  • 1
  • 1
dnozay
  • 23,846
  • 6
  • 82
  • 104
  • I'm not running it in a virtualenv, but the output of `pip freeze` contains `wxPython==2.9.4.0; wxPython-common==2.9.4.0` – beardc Oct 21 '12 at 16:36
  • I got it working with your last suggestion, though it's pretty tedious: `/usr/bin/pythonw2.7 /usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/runsnakerun/runsnake.py `. I thought I could just put `#! /usr/bin/pythonw2.7` in the first line to get it working, but apparently not. Anyways, thanks! – beardc Oct 21 '12 at 20:15
0

Try running runsnake outside of a virtualenv.

See detailed reasons here: http://wiki.wxpython.org/wxPythonVirtualenvOnMac

slashdottir
  • 7,835
  • 7
  • 55
  • 71