0

I have installed wxPython by following the instructions from this answer using the following command in Ubuntu 14.04

sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-doc wx2.8-examples wx2.8-headers wx2.8-i18n

Everything got installed properly.

But when I do import wx in my code, I get the following error.

Python 2.7.6 (default, Mar 22 2014, 22:59:38) [GCC 4.8.2] on linux2 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 

Do I have to install anything to use wxPython in my code?

Edit:

The directory in which wxPython is installed is in sys.path

$ pip show wxPython-common --- Metadata-Version: 1.1 Name: wxPython-common Version: 3.0.0.0 Summary: Cross platform GUI toolkit for Python Home-page: http://wxPython.org/ Author: Robin Dunn Author-email: Robin Dunn <[email protected]> License: wxWidgets Library License (LGPL derivative) Location: /usr/lib/python2.7/dist-packages Requires: 

From the above output we can see that it is installed in /usr/lib/python2.7/dist-packages and when I print sys.path this path is included.

$ python Python 2.7.6 (default, Mar 22 2014, 22:59:38) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print sys.path ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-i386-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client'] 

Edit2:

I have also made sure that I am using the correct version of python.

~$ which python /usr/bin/python ~$ ll /usr/bin/python lrwxrwxrwx 1 root root 9 Dec 21 2013 /usr/bin/python -> python2.7* 
3
  • 1
    I suspect that your sudo apt-get install is targeting a different python interpretter for some reason Commented Jun 3, 2015 at 17:20
  • @JoranBeasley I checked it. It is installing it for the correct python interpreter. Commented Jun 4, 2015 at 4:50
  • 1
    The pip show command shows the information for a wxPython 3.0 installation, is that a wx install which came with the system? It is definitely not the one you installed with apt get. Do you have two wxPython versions in your dist-packages folder? If yes, you would select between them using either wx.pth or wxversion on Windows, not sure if that also works on Linux. Check out: wiki.wxpython.org/… Commented Jun 4, 2015 at 7:05

4 Answers 4

1

Do you have the python-wxversion package installed? It includes a file that will select the default wxPython if you have more than one version installed, so it is optional so other versions can be selected. That is not done much anymore, but the file is still needed if you want to have the only installed wxPython be importable without sys.path modification.

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

1 Comment

I ended up compiling wxPython from source and I guess includes the wxversion. Now it works for me.
1

Just add this in the start of the program, it works for me, I was having the same problem.

import wxversion wxversion.select('3.0') import wx 

Comments

1

I fix this problem installing it with pip. Maybe the problem with brew is something about the paths and with pip the installation was successful and smooth.

Try this:

sudo pip install wxpython 

The sudo was necessary in my case.

Comments

0

Maybe the problem is that path to folder with wx is not in Python's sys.path ?

you can check it with

import sys print sys.path 

2 Comments

Python's sys.path includes the directory where wxPython is installed. Please check my edit, where I have added more information about it.
In sys.path should be something like that: /usr/lib/python2.7/dist-packages/wx-2.8 . So, try to find your wx folder and add path to it(including wx folder) to system path@Sudar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.