0

I want to run drpython but it can't find the wxpython library that I installed:

C:\Users\Niklas\Desktop\DrPython>python drpython.pyw
Traceback (most recent call last):
  File "drpython.pyw", line 35, in <module>
    import drpython
  File "C:\Users\Niklas\Desktop\DrPython\drpython.py", line 48, in <module>
    import wx, wx.stc
ImportError: No module named wx

What can I do to resolve this? I use Windows 7 and on Ubuntu this is working. I installed wx but the python interpreter can't find the wx module:

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named wx
>>>

My path is

C:\Users\Niklas>echo %PATH%
C:\Program Files (x86)\ActiveState Komodo IDE 6\;C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program
Files (x86)\Hewlett-Packard\HP ProtectTools Security Manager\Bin\;C:\Program Fil
es (x86)\Intel\Services\IPT\;C:\Program Files\Mercurial\;C:\Program Files\Tortoi
seHg\;C:\python27\;C:\Program Files (x86)\Google\google_appengine\;C:\python27\L
ib\site-packages;C:\python27

My sys.path is

>>> import sys
>>> sys.path
['', 'C:\\Windows\\system32\\python27.zip', 'C:\\python27\\DLLs', 'C:\\python27\
\lib', 'C:\\python27\\lib\\plat-win', 'C:\\python27\\lib\\lib-tk', 'C:\\python27
', 'C:\\python27\\lib\\site-packages']
>>>
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
  • 1
    what happens if you do `import wx` in the python interpreter console. Do you have wxPython installed on your win7 python installation? – joaquin Jan 26 '12 at 08:00
  • `no module named wx` even though I did install wx – Niklas Rosencrantz Jan 26 '12 at 08:33
  • 1
    0) check if you can import in the same way other third party libraries (p.e numpy). If not, check if `C:\python27` and `C:\python27\Lib\site-packages` (or the corresponding paths for your computer) are listed in the PATH environment variable of your system . 1) if yes, be sure you installed the correct version of wxpython (32 or 64 bits) for the corresponding python 32 or 64 bit. Also Look at the site-packages and check wxpython is there. Check if there is also a wx.pth file. this file redirect the import to the `wx` name to the actual `wx-2.8-etc` package. – joaquin Jan 26 '12 at 08:57
  • I can't import any third-party modules or libraries. importing numpy fails (I didn't install numpy) even though both python and site-packages are in my path (see updated question) – Niklas Rosencrantz Jan 26 '12 at 10:05
  • 1
    are wx-2.8-... folder and the wx.pth file **physically** in your site-packages folder? – joaquin Jan 26 '12 at 12:49
  • @joaquin: I'll take a look this aternoon since I'm not physically at that computer right now. I'm using Linux right now where to the problem doesn't appear. I supppose I could always just drop the wb library next to my drpython files but that would duplicate the installation and is not DRY. – Niklas Rosencrantz Jan 27 '12 at 05:56
  • 1
    "just drop the wb library next to my drpython files" No, you can not **just** do that. You would need some tweaking that would make situation still more complex. In windows, to install python and wxpython from the binary installers is a breeze, a 2 * 2 double-click. – joaquin Jan 27 '12 at 06:41
  • It worked to reinstall. Thanks for great help here. – Niklas Rosencrantz Jan 27 '12 at 13:13

1 Answers1

2

What's relevant here is sys.path - not the environment %PATH%.

E.g.:

In [45]: sys.path
Out[45]: 
['',
 '/usr/bin',
 '/usr/lib/python2.7/site-packages/django_debug_toolbar-0.9.1-py2.7.egg',
 '/usr/lib/python27.zip',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7/site-packages',
 '/usr/lib/python2.7/site-packages/Numeric',
 '/usr/lib/python2.7/site-packages/PIL',
 '/usr/lib/python2.7/site-packages/gst-0.10',
 '/usr/lib/python2.7/site-packages/gtk-2.0',
 '/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info',
 '/usr/lib/python2.7/site-packages/wx-2.8-gtk2-unicode',
 '/usr/lib/python2.7/site-packages/IPython/Extensions',
 u'/home/alf/.ipython']

If you want to influence sys.path from the environment, ther relevant variable is %PYTHONPATH%.

You can also import a module given it's full path - but it gets trickier - see this thread

Community
  • 1
  • 1
Alien Life Form
  • 1,884
  • 1
  • 19
  • 27
  • 1
    then how comes in windows neither py3k or py2k installers like activestate or python.org set the system PYTHONPATH variable (but the PATH variable) and it works perfectly ? – joaquin Jan 26 '12 at 12:44
  • 1
    Because, pythonpath adds to whatever is already in sys.path (see http://docs.python.org/tutorial/modules.html); usually it is not needed at all. In fact, if I had to guess the core reason for the behavior you are wintnessing, I'd say it's multiple python installs. – Alien Life Form Jan 26 '12 at 14:20
  • 1
    @AlienLifeForm, That was the point of my retorical question. Many answers and blogs tell new users they have to set PYTHONPATH in windows for solving import issues. And then that user have two problems...but where PYTHONPATH is ?, etc, etc. There are even blogs that tell the poor guy to regedit and tweak on the windows registry for that... I **never** had to set PYTHONPATH to have a normal python installation running in python. Maybe it is needed in other OSes but in windows to install anything from binary installers is 99.9% of the time just two clicks away from working. – joaquin Jan 27 '12 at 06:52
  • @joaquin: PYTHONPATH is not needed on UNICes any more than it is needed in windows, not even for multiple python installs It (may) come in handy if you wan to replace standard modules with your versions, or if you are forced to install in non standard paths,etc. but even for that I think there are more reliable methods. – Alien Life Form Jan 30 '12 at 15:45