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
7
  • Can you please detail how you installed runsnake? Commented Oct 21, 2012 at 16:57
  • do you mean pip freeze shows both RunSnakeRun and wxPython==2.9.4.0 and wxPython-common==2.9.4.0? Commented Oct 21, 2012 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...". Commented Oct 21, 2012 at 17:04
  • what is sys.executable in/outside runsnake? Commented Oct 21, 2012 at 17:36
  • /usr/local/Cellar/python/2.7.3/bin/python in both cases (homebrew python) Commented Oct 21, 2012 at 17:51

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
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 <filename>. I thought I could just put #! /usr/bin/pythonw2.7 in the first line to get it working, but apparently not. Anyways, thanks!
0

Try running runsnake outside of a virtualenv.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.