How to import wx on Ubuntu 16.04

7,084

In Ubuntu 16.04 and later open the terminal and type:

sudo apt install python-wxgtk3.0 python-wxgtk3.0-dev  

Then check if wx works in Python 2.x as follows:

$ python
>>> import wx

Example code

  1. Save the following code as wxPython-window.py

  2. Make it executable.

  3. Change directories using cd to the parent directory of wxPython-window.py

  4. Run the code with ./wxPython-window.py

    #!/usr/bin/python
    
    import wx      
    app = wx.App()
    frame = wx.Frame(None, -1, 'win.py')
    frame.Show()
    app.MainLoop()  
    
Share:
7,084

Related videos on Youtube

Rohan Raj
Author by

Rohan Raj

Updated on September 18, 2022

Comments

  • Rohan Raj
    Rohan Raj over 1 year

    I have tried installing it using apt-get:

    sudo apt-get install python-wxgtk3.0
    

    But still when I run a py script with import wx it throws an error 'no module named wx' on Python 2.x and Python 3.x

    I also tried installing it using pip:

    pip install wxpython
    

    which gives me an error saying failed building wheel for wxpython.

    I also tried building wxpython from source.

    but it shows a network error whenever I try to download the tar.gz file. I have unsuccesfully tried downloading it from multiple networks.

    Please help.

    • lenhhoxung
      lenhhoxung about 6 years
      Probably you're using a virtual environment.
    • lenhhoxung
      lenhhoxung about 6 years
      If that's the case, use this command: pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubun‌​tu-16.04 wxPython
  • Rohan Raj
    Rohan Raj over 6 years
    Same issue, doesn't work.