56

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

Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
Luke Bream
  • 855
  • 2
  • 10
  • 15
  • "When I import wx I get the error message" -> where are you doing the import step (i.e. please provide more details) and are you sure that you're using Python2.7 when you do the import (I'm wondering if your default Python is another version)? – sgallen Dec 22 '11 at 21:07
  • I have been running that code on the IDLE Python GUI `>>> import wx Traceback (most recent call last): File "", line 1, in import wx ImportError: No module named wx` – Luke Bream Dec 22 '11 at 21:14
  • Can you import other modules? Only wx fails ?. If this is the case, is there a wx.pth file in your site-packages folder ? – joaquin Dec 22 '11 at 21:36
  • yes I can import all my other modules and packages and the wx.pth file is present in site-packages...Its just this sone Im having probles with.. – Luke Bream Dec 22 '11 at 21:52
  • 1
    Ops! what you describe is the correct setup... It should work... Did you installed from a binary from the official wxpython site? What was the name of if ? A different question, can you import wx from a python shell open in the windows console (instead of from idle). – joaquin Dec 22 '11 at 22:03
  • thats interesting....YES I can import wx from the windows console ??? thats a bit strange.... what does that mean ?? why is it not working inside IDLE.. – Luke Bream Dec 22 '11 at 22:07
  • Joaquin... thanks so much that has fixed the problem... I closed IDLE and restarted it and it is now accepting the imprt wx statement....Yipee !! – Luke Bream Dec 22 '11 at 22:11
  • 2
    You know? I have the least idea of why is now working and not before. Maybe you didnt restarted idle after installing wx ? um... – joaquin Dec 22 '11 at 22:18
  • hello discussion from the distant past. same problem. restarting idle fixed it – Snesticle Oct 06 '15 at 23:54

16 Answers16

54

Ubuntu:

sudo apt-get install python-wxtools
Giuseppe Urso
  • 699
  • 5
  • 5
29

For Windows and MacOS, Simply install it with pip

pip install -U wxPython

Reference: Official site

Shivam Agrawal
  • 801
  • 9
  • 5
  • 2
    for linux too, this is the best way – rayzinnz Mar 25 '21 at 05:32
  • As per the site, for linux distro dependent, example: pip install -U \ -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \ wxPython – Meep Sep 30 '21 at 19:28
21

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\

philshem
  • 24,761
  • 8
  • 61
  • 127
frmdstryr
  • 20,142
  • 3
  • 38
  • 32
  • 1
    This worked for me after I installed wx from [Unofficial Windows Binaries for Python Extension Packages](http://www.lfd.uci.edu/~gohlke/pythonlibs/) – philshem Feb 17 '17 at 09:45
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...

Jason Sundram
  • 12,225
  • 19
  • 71
  • 86
unrealsoul007
  • 3,809
  • 1
  • 17
  • 33
4

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.

Riccardo Volpe
  • 1,471
  • 1
  • 16
  • 30
4

This worked for me

pip install --user -U wxPython
raw_hitt
  • 719
  • 5
  • 21
2

I too face the same problem, I like to share which I was faced so it can be helpful for anyone. In my case I have installed both python2. 7 and python3, and tested the application in python3 after some analysis I used

pip show wxpython-common

to find the location of wx which was in

/usr/lib/python2.7/dist-packages

so i understood in my case wx will work only in python2.7 environment

Janarthanan Ramu
  • 1,331
  • 16
  • 17
2

In fedora you can use following command to install wx

pip install -U \
  -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \
  wxPython
Ross Rogers
  • 23,523
  • 27
  • 108
  • 164
Nilesh Pawar
  • 655
  • 7
  • 12
1

I'm on 64-bit Windows 7 and went to:

https://wxpython.org/

Then downloaded the exe for my system, installed it, and it worked for me.

Samuel
  • 8,063
  • 8
  • 45
  • 41
1

Download the .whl file from this link.

The name of the file is: wxPython‑3.0.2.0‑cp27‑none‑win32.whl for Windows 32 bit and python 2.7 and wxPython‑3.0.2.0‑cp27‑none‑win_amd64.whl for Windows 64 bit and python 2.7.

Then in the command prompt: pip install location-of-the-above-saved-file

JoshuaRLi
  • 1,665
  • 14
  • 23
Forouq Khonsari
  • 59
  • 1
  • 1
  • 3
1

Just open your terminal and run this command thats for windows users pip install -U wxPython

for Ubuntu user you can use this

pip install -U \
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \
wxPython
0

You may check if you have the directory where are the packages of Python (in my machine, this dir is C:\Python27\lib\site-packages) in the Path variable on Windows. If Python's path environment variable does not have this directory, you will not find the packages.

0

If you do not have wx installed on windows you can use :

 pip install wx
Chem-man17
  • 1,700
  • 1
  • 12
  • 27
michael
  • 33
  • 1
-1

I restart the IDLE and works for me!

josedlujan
  • 5,357
  • 2
  • 27
  • 49
-1

Make sure you choose the right project intepreter in the compiler. I used the Pycharm, and I encountered the same problem. And it was solved by choose the right intepreter. Thisvideo may help you.

Massifox
  • 4,369
  • 11
  • 31
-3

Generally, package names in the site-packages folder are intended to be imported using the exact name of the module or subfolder.

If my site-packages folder has a subfolder named "foobar", I would import that package by typing import foobar.

One solution might be to rename site-packages\wx-2.8-msw-unicode to site-packages\wx.

Or you could add C:\Python27\Lib\site-packages\wx-2.8-msw-unicode to your PYTHONPATH environment variable.

John Gordon
  • 29,573
  • 7
  • 33
  • 58
  • 2
    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. – joaquin Dec 22 '11 at 21:30
  • 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 ! – Luke Bream Dec 22 '11 at 21:49