2

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.

2
  • Probably you're using a virtual environment.
    – lenhhoxung
    Mar 27, 2018 at 15:34
  • If that's the case, use this command: pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 wxPython
    – lenhhoxung
    Mar 27, 2018 at 15:36

3 Answers 3

1

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()  
    
0

Press Ctrl+Alt+T and type the following:

sudo apt-get install python-wxtools
1
  • Same issue, doesn't work.
    – Rohan Raj
    Nov 8, 2017 at 14:20
0

please check if you have all necessary libraries installed (here is a link for different OS like Ubuntu 16 Libs needed for wx)

# Install necessary development tools, libs, etc.
apt-get install -y build-essential dpkg-dev

apt-get install -y libgtk2.0-dev libgtk-3-dev
apt-get install -y libjpeg-dev libtiff-dev \
    libsdl1.2-dev libgstreamer-plugins-base0.10-dev \
    libgstreamer-plugins-base1.0-dev \
    libnotify-dev freeglut3 freeglut3-dev libsm-dev \
    libwebkitgtk-dev libwebkitgtk-3.0-dev libwebkit2gtk-4.0-dev \
    libxtst-dev

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .