Problem and Solution for Installing wxPython on Ubuntu 20.04

  sonic0002        2020-09-09 05:32:35       24,234        7    

When we try to install wxPython lib on Ubuntu system to do software GUI development,

most of time we may meet some installation and lib dependency problems. For the latest Ubuntu version, the problems still happen. Below are some common problems which happened frequently and their solution:

---------------------------------------------------------------------------------------------------------------

Problem [1]: Install wxPython on Ubuntu 20.04 fail because of dependency package Gtk is not installed.

Error Message:

No package 'gtk+-3.0' found
 Package gthread-2.0 was not found in the pkg-config search path.
 Perhaps you should add the directory containing `gthread-2.0.pc'
 to the PKG_CONFIG_PATH environment variable
 No package 'gthread-2.0' found
 no
 *** Could not run GTK+ test program, checking why...
 *** The test program failed to compile or link. See the file config.log for the
 *** exact error that occurred. This usually means GTK+ is incorrectly installed.

OS Platform : Ubuntu 16.04, Ubuntu 18.04, Ubuntu 20.04.

Type: Dependency package not installed.

Solution:

  • Solution[1]: Install wxPython package with Gtk package bind in:
    sudo apt install libgtk-3-dev
    
    sudo apt-get install python-wxgtk3.0​
  • Solution [2] : If solution[1] shows install error for latest Ubuntu version(20.04), install the related dependency package:
    sudo apt-get install python3-wxgtk4.0 python3-wxgtk-webview4.0 python3-wxgtk-media4.0​
  • Solution[3] : After finished the step in solution[2] and also try pip-installation "pip install wxPython". If the pip-installation still not work, install the specific wxPython package(it is compatible for 20.04 ):
    sudo pip3 install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 wxPython​

---------------------------------------------------------------------------------------------------------------

Problem [2]: Successfully installed wxPython package but got error during import it in program.

Error Message:

python 3.8.2 (default, Jul 16 2020, 14:00:26) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
 File "", line 1, in 
 File "/usr/local/lib/python3.8/dist-packages/wx/__init__.py", line 17, in 
 from wx.core import *
 File "/usr/local/lib/python3.8/dist-packages/wx/core.py", line 12, in 
 from ._core import *
ImportError: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory

OS Platform : Ubuntu 20.04.

Type: wxPython_v4.x related lib SDL2-X packages are not installed.

Solution:

sudo apt-get install git curl libsdl2-mixer-2.0-0 libsdl2-image-2.0-0 libsdl2-2.0-0

---------------------------------------------------------------------------------------------------------------

Problem [3]: Successfully installed wxPython package but got error during import it in program.

Error Message:

Python 3.8.2 (default, Jul 16 2020, 14:00:26) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
 File "", line 1, in 
 File "/usr/local/lib/python3.8/dist-packages/wx/__init__.py", line 17, in 
 from wx.core import *
 File "/usr/local/lib/python3.8/dist-packages/wx/core.py", line 12, in 
 from ._core import *
ImportError: libpng12.so.0: cannot open shared object file: No such file or directory

OS Platform : Ubuntu 20.04.

Type: wxPython_v4.x related lib png12/14 packages are not installed.

Solution:

Download the lib deb "libpng12-0_1.2.54-1ubuntu1b_amd64.deb" from below link :

https://www.dropbox.com/s/79x3imq73tcqyw4/libpng12-0_1.2.54-1ubuntu1b_amd64.deb?dl=0 
or 
https://github.com/LiuYuancheng/Power_Generator_Manager/blob/master/lib/libpng12-0_1.2.54-1ubuntu1b_amd64.deb

Install the lib by cmd:

sudo dpkg -i libpng12-0_1.2.54-1ubuntu1b_amd64.deb

Note: This post is authorized to republish here by Yuancheng Liu, Systems Software Engineer at ZycraftUSV.PTE.LTD. Original post is here.

UBUNTU 20.04  WXPYTHON  PYTHON 

       

  RELATED


  7 COMMENTS


mario [Reply]@ 2021-01-15 05:56:06

tx, your solution for problem 2 fixed mine :p

 

Ke Pi [Reply]@ 2021-01-18 09:00:45

great to hear about it

Got [Reply]@ 2021-02-01 19:30:58

Thank you so much. I can install wxPython now.

Ke Pi [Reply]@ 2021-02-12 07:30:26

Awesome to hear abt it

Anonymous [Reply]@ 2022-11-16 01:08:23

Have you ever met this question : error: [Errno 2] No such file or directory: 'build/lib.linux-x86_64-3.8/wx/libwx_baseu-3.0.so'

Anonymous [Reply]@ 2023-01-26 08:55:45

Have you ever seen error like this?

 

Collecting wxPython

  Using cached wxPython-4.2.0.tar.gz (71.0 MB)

  Preparing metadata (setup.py) ... error

  error: subprocess-exited-with-error

  

  × python setup.py egg_info did not run successfully.

  ? exit code: 1

  ??> [8 lines of output]

      Traceback (most recent call last):

        File "<string>", line 2, in <module>

        File "<pip-setuptools-caller>", line 34, in <module>

        File "/tmp/pip-install-844jm5oc/wxpython_bf2f77e2c26742cd8bea2075a42c522f/setup.py", line 27, in <module>

          from buildtools.config import Config, msg, opj, runcmd, canGetSOName, getSOName

        File "/tmp/pip-install-844jm5oc/wxpython_bf2f77e2c26742cd8bea2075a42c522f/buildtools/config.py", line 

Anonymous [Reply]@ 2023-01-26 08:56:35

My error just like this 

 

Collecting wxPython

  Using cached wxPython-4.2.0.tar.gz (71.0 MB)

  Preparing metadata (setup.py) ... error

  error: subprocess-exited-with-error

  

  × python setup.py egg_info did not run successfully.

  ? exit code: 1

  ??> [8 lines of output]

      Traceback (most recent call last):

        File "<string>", line 2, in <module>

        File "<pip-setuptools-caller>", line 34, in <module>

        File "/tmp/pip-install-844jm5oc/wxpython_bf2f77e2c26742cd8bea2075a42c522f/setup.py", line 27, in <module>

          from buildtools.config import Config, msg, opj, runcmd, canGetSOName, getSOName

        File "/tmp/pip-install-844jm5oc/wxpython_bf2f77e2c26742cd8bea2075a42c522f/buildtools/config.py", line 30, in <module>

          from attrdict import AttrDict

      ModuleNotFoundError: No module named 'attrdict'

      [end of output]

  

  note: This error originates from a subprocess, and is likely not a problem with pip.

error: metadata-generation-failed

 

× Encountered error while generating package metadata.

??> See above for output.

 

note: This is an issue with the package mentioned above, not pip.

hint: See above for details.

 



  RANDOM FUN

The truth about software development