pythonpython-2.7debianwxpythonwxwidgets

"ImportError: No module named wx" on Debian Jessie Python 2.7 after installing python-wxtools


I'm really confused as to why this fails as I followed the directions for Installing on Ubuntu Or Debian.

In the terminal, I tried running:

apt-get install python-wxtools

which succeeds.

But when I try to import it in Python:

import wx

it fails with the error:

ImportError: No module named wx

I'm not sure if this is related, but it also installs v3.0 (which I thought was the version for Phoenix/Python3?) while being dependent on Python 2.7.

For reference, I tried this off the python:2.7.10 Docker image, which is built off Debian Jesse. You can reproduce as such:

$ docker run -it python:2.7.10 bash
root@b3ba556667ac:/# apt-get install python-wxtools
root@b3ba556667ac:/# python
>>> import wx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named wx

Solution

  • For posterity1, back in December 2015, I ended up solving this by migrating my Dockerfile from a python:2.7 base to a ubuntu:14.04 base.

    After installing Python, the installation instructions worked the same, but I no longer received an import error:

    FROM ubuntu:14.04
    
    # install Python
    RUN apt-get update && apt-get install -y --no-install-recommends \
      python-pip && \
      apt-get autoremove -y
    
    # install wxPython
    RUN apt-get install -y --no-install-recommends python-wxtools
    

    1. This is more of a workaround than a fix, but given this never got an answer and is quite dated now, I figured I'd show the workaround at least for posterity.