Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 557
beardc Avatar asked Jul 22 '26 16:07

beardc


1 Answers

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

like image 169
dnozay Avatar answered Jul 25 '26 05:07

dnozay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!