wxPython 4.2.1, ubuntu 22.04 - installation via pip fails

Hi,

when trying to install wxPython 4.2.1 on ubuntu 22.04 (during the azure devops ci/cd build), I’m getting the following error:

    Running command: build
    Running command: build_wx
    wxWidgets build options: ['--wxpython', '--unicode', '--gtk3']
    Configure options: ['--enable-unicode', '--with-gtk=3', '--enable-sound', '--enable-graphics_ctx', '--enable-display', '--enable-geometry', '--enable-debug_flag', '--enable-optimise', '--disable-debugreport', '--enable-uiactionsim', '--enable-autoidman', '--with-sdl']
    /tmp/pip-install-8wugv98h/wxpython_40415c21d3f9425c97fee9a6965dcedf/ext/wxWidgets/configure --enable-unicode --with-gtk=3 --enable-sound --enable-graphics_ctx --enable-display --enable-geometry --enable-debug_flag --enable-optimise --disable-debugreport --enable-uiactionsim --enable-autoidman --with-sdl
    checking build system type... x86_64-pc-linux-gnu
    checking host system type... x86_64-pc-linux-gnu
    checking for toolkit... gtk
    checking for gcc... gcc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables...
    checking whether we are cross compiling... no
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ISO C89... none needed
    checking whether we are using the Intel C compiler... no
    checking how to run the C preprocessor... gcc -E
    checking for grep that handles long lines and -e... /usr/bin/grep
    checking for egrep... /usr/bin/grep -E
    checking whether gcc needs -traditional... no
    checking for g++... g++
    checking whether we are using the GNU C++ compiler... yes
    checking whether g++ accepts -g... yes
    checking whether we are using the Intel C++ compiler... no
    checking whether we are using the Sun C++ compiler... no
    checking for ar... ar
    checking for ANSI C header files... yes
    checking for sys/types.h... yes
    checking for sys/stat.h... yes
    checking for stdlib.h... yes
    checking for string.h... yes
    checking for memory.h... yes
    checking for strings.h... yes
    checking for inttypes.h... yes
    checking for stdint.h... yes
    checking for unistd.h... yes
    checking for langinfo.h... yes
    checking for wchar.h... yes
    checking for sys/select.h... yes
    checking for cxxabi.h... yes
    checking for an ANSI C-conforming const... yes
    checking for inline... inline
    checking size of short... 2
    checking size of void *... 8
    checking size of int... 4
    checking size of long... 8
    checking size of size_t... 8
    checking size of long long... 8
    checking size of wchar_t... 4
    checking for va_copy... yes
    checking for _FILE_OFFSET_BITS value needed for large files... 64
    checking if large file support is available... yes
    checking for _LARGEFILE_SOURCE value needed for large files... no
    checking whether byte ordering is bigendian... no
    checking for std::wstring in <string>... yes
    checking for std::istream... yes
    checking for std::ostream... yes
    checking for type_traits... yes
    checking for __sync_xxx_and_fetch builtins... yes
    checking for libraries directories... /usr/lib/x86_64-linux-gnu /usr/lib
    checking for cos... no
    checking for floor... no
    checking if floating point functions link without -lm... no
    checking for sin... yes
    checking for ceil... yes
    checking if floating point functions link with -lm... yes
    checking for strtoull... yes
    checking for pkg-config... /usr/bin/pkg-config
    checking pkg-config is at least version 0.9.0... yes
    checking for LIBPCRE... yes
    checking for zlib.h >= 1.1.4... yes
    checking for zlib.h... (cached) yes
    checking for deflate in -lz... yes
    checking for png.h > 0.90... yes
    checking for png.h... (cached) yes
    checking for png_sig_cmp in -lpng... yes
    checking for jpeglib.h... yes
    checking for jpeg_read_header in -ljpeg... yes
    checking for jbg_dec_init in -ljbig... yes
    checking for LIBTIFF... yes
    checking for expat.h... yes
    checking if expat.h is valid C++ header... yes
    checking for XML_ParserCreate in -lexpat... yes
    checking for LIBCURL... not found
    checking for GTK+ version...
    checking for pkg-config... (cached) /usr/bin/pkg-config
    checking pkg-config is at least version 0.16... yes
    checking for GTK+ - version >= 3.0.0... Package gtk+-3.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gtk+-3.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gtk+-3.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.
    configure: error:
    The development files for GTK+ were not found. For GTK+ 2, please
    ensure that pkg-config is in the path and that gtk+-2.0.pc is
    installed. For GTK+ 1.2 please check that gtk-config is in the path,
    and that the version is 1.2.3 or above. Also check that the
    libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
    --libs' are in the LD_LIBRARY_PATH or equivalent.
    
    Error running configure
    ERROR: failed building wxWidgets
    Traceback (most recent call last):
      File "/tmp/pip-install-8wugv98h/wxpython_40415c21d3f9425c97fee9a6965dcedf/build.py", line 1563, in cmd_build_wx
        wxbuild.main(wxDir(), build_options)
      File "/tmp/pip-install-8wugv98h/wxpython_40415c21d3f9425c97fee9a6965dcedf/buildtools/build_wxwidgets.py", line 379, in main
        exitIfError(wxBuilder.configure(dir=wxRootDir, options=configure_opts),
      File "/tmp/pip-install-8wugv98h/wxpython_40415c21d3f9425c97fee9a6965dcedf/buildtools/build_wxwidgets.py", line 72, in exitIfError
        raise builder.BuildError(msg)
    buildtools.builder.BuildError: Error running configure
    Finished command: build_wx (0m8.82s)
    Finished command: build (0m8.82s)
    Command '"/usr/share/miniconda/envs/wx_utils/bin/python" -u build.py build' failed with exit code 1.
    [end of output]

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

What could be done in order to get wxPython 4.2.1 installable on ubuntu (note - previously used version 4.1.1 was working fine, but installation was performed via conda package, and not via pip. For 4.2.1 I was not able to find conda package yet)

Many Thanks in Advance

Serhiy Yevtushenko

Further investigation has shown, that if one executes following commands before installation, then it works out:

 sudo add-apt-repository ppa:gnome3-team/gnome3-staging
sudo add-apt-repository ppa:gnome3-team/gnome3
sudo apt update
sudo apt-get install libgtk-3-dev

However, the build time for environment on azure-devops ubuntu machines takes then about 45 minutes for building environment, and for the same environment, but with version 4.1.1 (installed via conda), it was taking 4 minutes, so, I’m getting the impression that something is wrong.

Could someone please advise, what is done not correctly in this case?

Yes, as you figured out, you were missing the GTK+ 3 development packages in your first instance. And yes, taking about 45 minutes is to be expected when installing wxPython this way is to be expected because you are having to compile the entirety of wxWidgets and wxPython. The reason it has to be compiled is that there are no wheels for wxPython for Linux systems on PyPI because there are too many variations in Linux distributions.

I would not recommend installing wxPython this way in a CI/CD environment. Instead, I would recommend copying one of the wheels from here:
https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04/
and saving it in your CI/CD environment somewhere where you can download it each time to install. I would not recommend installing it directly from extras.wxpython.org as that’s Robin’s site which is probably not configured for massive numbers of downloads.

I don’t really know anything about conda, sorry, but presumably they must be generating prebuilt packages similar to wheels, and it seems they probably haven’t built one for wxPython 4.2.1 yet.

Hi, Scott,

thank you very much for your explanation.

Serhiy Yevtushenko

Hi, Scott.

I have followed your advice and tried using pre-built wheel, reference to which you have posted (cached locally). However, I’m currently facing the following problem: while wheel installation via pip seems to be working fine, I’m getting the following exceptions when trying to run tests, which are exercising wxPython:

src/python/wx_utils/test_utils.py:1: in <module>

/usr/share/miniconda/envs/wx_utils/lib/python3.9/site-packages/wx/__init__.py:12: in <module>
    __version__ = wx.__version__.VERSION_STRING
 AttributeError: partially initialized module 'wx' has no attribute '__version__' (most likely due to a circular import)

Such a problem does not appear in case, when wxPython is installed from source distribution (when compilations takes about 50 minutes).

Could you advice, what could be the reason for such a behavior?

Many thanks in advance

Serhiy

Sorry, I don’t have any ideas about that off the top of my head.

Another possible solution is that you could build your own wheel in your environment and then save/restore it from cache to speed up the process.

Thank you for answer and suggestions, Scott.

I have found a similar bug report with previous version of wxPython - Bug #1816462 ""Error: unable to create the python console"" : Bugs : KiCad. It seems to indicate, that either something is incorrect with installation location or one need to install python3-wxgtk4.0 before.

I will try the second way to see, whether it will help

Kind Regards
Serhiy

You should definitely not need python3-wxgtk4.0 installed. That will install Ubuntu’s package for wxPython, which in 22.04 is wxPython 4.0.7. That could be a solution, too, instead of trying to install a wheel, if you don’t need 4.2.1.