Python ImportError: No module named wx

177,537

Solution 1

Ubuntu:

sudo apt-get install python-wxtools

Solution 2

For Windows and MacOS, Simply install it with pip

pip install -U wxPython

Reference: Official site

Solution 3

Windows:

  1. Go to C:\Python27\Lib\site-packages\ find the folder wx-<version>-msw or similar

  2. Move the wx from the above folder to C:\Python27\Lib\site-packages\

Solution 4

I had the same error today but I tried something and surprisingly it worked. In the site packages folder there will be a file named wx.pth. Open it using notepad and its contents would be like "wx-2.8-msw-unicode"

It is basically the name of the folder containing wxpython. Delete this using Ctrl + A and copy the name of the folder from the site packages and paste it here even if it is the same.

Sounds weird but maybe the original file contained a hidden character...

Solution 5

I had the same problem for a PyMOL plugin that required the wx module, though I installed wxpython by downloading its package from here (Unofficial Windows Binaries for Python Extension Packages) and installing it with the command:

pip install .\wxPython-3.0.2.0-cp27-none-win_amd64.whl

For some reason it gave me that error, for which I uninstalled it with:

pip uninstall wxPython

and then I downloaded it from here (wxPython 4.0.0a1) and reinstalled:

pip install .\wxPython-4.0.0a1-cp27-cp27m-win_amd64.whl

The error at this point has not been presented anymore.

Share:
177,537
Luke Bream
Author by

Luke Bream

Updated on July 09, 2022

Comments

  • Luke Bream
    Luke Bream 6 months

    Im sorry to ask this question again. I have searched and found endles repeats of it both on stackoverflow and also on general google search. Unfortunatly I just cant get my system sorted.

    I have the following:

    C:\Python27\Lib\site-packages\wx-2.8-msw-unicode
    

    this folder contains the wx folder and also wx & wxPython folders which each contain the _init_.py files

    When I import wx I get the error message "no module named wx"

    What do I need to do in order to get Python to find the relevant files to allow me to "import wx" succesfully

  • joaquin
    joaquin about 11 years
    please, don't do that, the name is correct. If you installation has been done properly there should be a file wx.pth in site-packages pointing to that folder name.
  • Luke Bream
    Luke Bream about 11 years
    Hi....I have checked the site-packages folder and I do have the wx.pth file present....and it contains the follwoing single line wx-2.8-msw-unicode any suggestions for sorting this would be really appreciated !
  • Mateusz
    Mateusz over 6 years
    he uses windows, not ubuntu/debian
  • Samuel
    Samuel almost 6 years
    This failed with compile errors for me, using Python 2.7.
  • philshem
    philshem almost 6 years
    This worked for me after I installed wx from Unofficial Windows Binaries for Python Extension Packages
  • philshem
    philshem almost 6 years
    If the pip installation fails, you should install the binary from lfd.uci.edu/~gohlke/pythonlibs
  • philshem
    philshem almost 6 years
    FYI - this installation requires windows admin rights
  • paxdiablo
    paxdiablo almost 4 years
    The fact OP has in the question C:\Python27\Lib\site-packages\wx-2.8-msw-unicode means this answer will be rather less than useful.
  • sijo0703
    sijo0703 over 3 years
    This command worked for me:: pip install wxPython
  • Giuseppe Urso
    Giuseppe Urso over 3 years
    Yes but that's because python 2.7 is default on your system, try pip3
  • Nelda.techspiress
    Nelda.techspiress almost 2 years
  • rayzinnz
    rayzinnz almost 2 years
    for linux too, this is the best way
  • Meep about 1 year
    As per the site, for linux distro dependent, example: pip install -U \ -f extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \ wxPython