beardc
beardc

Reputation: 21063

Python script shows different pythonpath

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

Upvotes: 3

Views: 908

Answers (2)

slashdottir
slashdottir

Reputation: 8516

Try running runsnake outside of a virtualenv.

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

Upvotes: 0

dnozay
dnozay

Reputation: 24304

  • 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.

Upvotes: 1

Related Questions