Reputation: 19992
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*
Upvotes: 0
Views: 4500
Reputation: 11
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.
Upvotes: 1
Reputation: 11
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
Upvotes: 1
Reputation: 6206
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.
Upvotes: 1
Reputation: 2907
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
Upvotes: 0