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']
>>>
8
  • 1
    what happens if you do import wx in the python interpreter console. Do you have wxPython installed on your win7 python installation? Commented Jan 26, 2012 at 8:00
  • no module named wx even though I did install wx Commented Jan 26, 2012 at 8: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. Commented Jan 26, 2012 at 8:57
  • 1
    are wx-2.8-... folder and the wx.pth file physically in your site-packages folder? Commented Jan 26, 2012 at 12:49
  • 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. Commented Jan 27, 2012 at 6:41

1 Answer 1

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

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

4 Comments

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 ?
Because, pythonpath adds to whatever is already in sys.path (see 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.
@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: 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.

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.