Incompatible with Python 3.12

Trying to install wxPython via pip, it’s the pyenv version with Python 3.12.

➜  ~ which python
~/.pyenv/shims/python
➜  ~ python --version
Python 3.12.0

But obtained the following ERROR messages:

....
      copying /tmp/pip-install-_4fx4uwm/wxpython_71ce0814de1541c1b4f9035540efa799/build/wxbld/gtk3/lib/libwx_gtk3u_richtext-3.2.so.0 --> /tmp/pip-install-_4fx4uwm/wxpython_71ce0814de1541c1b4f9035540efa799/wx/libwx_gtk3u_richtext-3.2.so.0
      Running command: build_others
      ~/.pyenv/versions/latest/bin/python setup-wxsvg.py build_ext --inplace
      Compiling wx/svg/_nanosvg.pyx because it changed.
      [1/1] Cythonizing wx/svg/_nanosvg.pyx
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
      for manipulating the SVG shape info in memory.
      """
      
      import sys
      
      cimport cython.object
              ^
      ------------------------------------------------------------
      
      wx/svg/_nanosvg.pyx:45:8: 'cython.object' is not a valid cython.* module
      Traceback (most recent call last):
        File "/tmp/pip-install-_4fx4uwm/wxpython_71ce0814de1541c1b4f9035540efa799/setup-wxsvg.py", line 54, in <module>
          modules = cythonize([module],
                    ^^^^^^^^^^^^^^^^^^^
        File "~/.local/lib/python3.12/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
          cythonize_one(*args)
        File "~/.local/lib/python3.12/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: wx/svg/_nanosvg.pyx
      Command '~/.pyenv/versions/latest/bin/python setup-wxsvg.py build_ext --inplace' failed with exit code 1.
      Finished command: build_others (0.879s)
      Finished command: build_py (2m23.587s)
      Finished command: build (3m25.847s)
      Command '"~/.pyenv/versions/latest/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.
  ERROR: Failed building wheel for wxPython
  Running setup.py clean for wxPython
Failed to build wxPython
ERROR: Could not build wheels for wxPython, which is required to install pyproject.toml-based projects
➜  ~ 

Can anybody help? Thanks

In this case, the problem is not Python 3.12, but newer versions of Cython (version 3.0+). I’ve already fixed this in the git repo, but there hasn’t been a new release yet.

You could try pip install Cython == 0.29.37 and then try installing wxPython again as a workaround.

1 Like

Thank you very much… Problem solved…

It’s worth noting this isn’t purely a cython issue.
In a brand new conda environment using python 3.12, I installed the recommended version of cython and then tried installing wxpython, but the wheel still fails.
Is there any chance we’ll be getting a release sometime that includes the fixes for python 3.12 compatibility?

Output of my install attempt for the curious:

$ pip install cython==0.29.37 && pip install wxpython 
Collecting wxpython
  Using cached wxPython-4.2.1.tar.gz (73.7 MB)
  Preparing metadata (setup.py) ... done
Collecting pillow (from wxpython)
  Using cached pillow-10.4.0-cp312-cp312-manylinux_2_28_x86_64.whl.metadata (9.2 kB)
Collecting six (from wxpython)
  Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)
Using cached pillow-10.4.0-cp312-cp312-manylinux_2_28_x86_64.whl (4.5 MB)
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Building wheels for collected packages: wxpython
  Building wheel for wxpython (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [77 lines of output]
      running bdist_wheel
      running build
      WARNING: Building this way assumes that all generated files have been
      generated already.  If that is not the case then use build.py directly
      to generate the source and perform the build stage.  You can use
      --skip-build with the bdist_* or install commands to avoid this
      message and the wxWidgets and Phoenix build steps in the future.
      
      "/home/ge2/miniforge3/envs/test/bin/python3.12" -u build.py build
      /tmp/pip-install-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/build.py:43: DeprecationWarning: dep_util is Deprecated. Use functions from setuptools instead.
        from distutils.dep_util import newer, newer_group
      Will build using: "/home/ge2/miniforge3/envs/test/bin/python3.12"
      3.12.5 | packaged by conda-forge | (main, Aug  8 2024, 18:36:51) [GCC 12.4.0]
      Python's architecture is 64bit
      cfg.VERSION: 4.2.1
      
      Running command: build
      Running command: build_wx
      /tmp/pip-install-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/buildtools/build_wxwidgets.py:83: SyntaxWarning: invalid escape sequence '\d'
        majorVersion = re.search("wx_major_version_number=(\d+)", configureText).group(1)
      /tmp/pip-install-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/buildtools/build_wxwidgets.py:84: SyntaxWarning: invalid escape sequence '\d'
        minorVersion = re.search("wx_minor_version_number=(\d+)", configureText).group(1)
      /tmp/pip-install-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/buildtools/build_wxwidgets.py:89: SyntaxWarning: invalid escape sequence '\d'
        releaseVersion = re.search("wx_release_number=(\d+)", configureText).group(1)
      /tmp/pip-install-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/buildtools/build_wxwidgets.py:428: SyntaxWarning: invalid escape sequence '\s'
        setupText, subsMade = re.subn(flag + "\s+?\d", "%s %s" % (flag, flags[flag]), setupText)
      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-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/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++... no
      checking for c++... no
      checking for gpp... no
      checking for aCC... no
      checking for CC... no
      checking for cxx... no
      checking for cc++... no
      checking for cl.exe... no
      checking for FCC... no
      checking for KCC... no
      checking for RCC... no
      checking for xlC_r... no
      checking for xlC... no
      checking whether we are using the GNU C++ compiler... no
      checking whether g++ accepts -g... no
      checking whether we are using the Intel C++ compiler... no
      checking whether we are using the Sun C++ compiler... no
      configure: error: C++ compiler is needed to build wxWidgets
      Error running configure
      ERROR: failed building wxWidgets
      Traceback (most recent call last):
        File "/tmp/pip-install-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/build.py", line 1563, in cmd_build_wx
          wxbuild.main(wxDir(), build_options)
        File "/tmp/pip-install-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/buildtools/build_wxwidgets.py", line 379, in main
          exitIfError(wxBuilder.configure(dir=wxRootDir, options=configure_opts),
        File "/tmp/pip-install-9qirq6bk/wxpython_52719d22b48244bfa8302f19ec60996b/buildtools/build_wxwidgets.py", line 72, in exitIfError
          raise builder.BuildError(msg)
      buildtools.builder.BuildError: Error running configure
      Finished command: build_wx (0.912s)
      Finished command: build (0.912s)
      Command '"/home/ge2/miniforge3/envs/test/bin/python3.12" -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.
  ERROR: Failed building wheel for wxpython
  Running setup.py clean for wxpython
Failed to build wxpython
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (wxpython)

Still waiting for a response from Robin:

EDIT: the comment that was recently added to that GitHub issue (under the RobinD42 username) was automatically generated when I included the link to the issue in this post. It does not mean that Robin has actually seen the post himself.

@glass-ships the relevant part of your error log is this:
configure: error: C++ compiler is needed to build wxWidgets