2

I'm trying to install wxPython on Ubuntu 16.04. I'm aware of this question and related answer. In particular, if I run a .py file that uses wxPython python3: wxPython_HelloWorld.py (copy-pasted from the introductory page to wxPython)

I get the error message:

Traceback (most recent call last):
  File "wxPython_HelloWorld.py", line 2, in <module>
    import wx
ImportError: No module named 'wx'

But python-wxgtk3.0 is installed. Indeed, running the installation command sudo apt-get install python-wxgtk3.0 returns:

Reading package lists... Done
Building dependency tree
Reading state information... Done
python-wxgtk3.0 is already the newest version (3.0.2.0+dfsg-1build1).
0 upgraded, 0 newly installed, 0 to remove and 79 not upgraded.

Does anybody have a guess about what the problem could be?

1 Answers1

3

You are trying to run the following Python script:

#!/usr/bin/env python
import wx
app = wx.App(False)
frame = wx.Frame(None, wx.ID_ANY, "Hello World") 
frame.Show(True) 
app.MainLoop()

The Python used for the REPL is not the same as the version of Python the script is being run in ( python ). In particular I was able to duplicate the error in your question with python3 as follows:

python3
>>> import wx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'wx'

The solution was to run the script in Python 2.x, which in my Ubuntu 16.04 is Python 2.7.12.

karel
  • 122,292
  • 133
  • 301
  • 332