Installing wxpython with Python 3.9 on Windows

I am unable to install wxpython on a WIndows 10 laptop after upgrading Python from 3.8.3 to 3.9.13 (32-bit). I have used wxpython succesfully for years. After going to my Python 3.9 directory and typing
python -m pip install wxpython
this is as much of the output as I could capture (it can’t all be redirected to a file and shoots off the screen too fast to see):

Collecting wxpython
Using cached wxPython-4.2.1-cp39-cp39-win32.whl (15.7 MB)
Collecting six
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting numpy
Using cached numpy-1.25.2-cp39-cp39-win32.whl (12.7 MB)
Collecting pillow
Using cached Pillow-10.0.0.tar.gz (50.5 MB)
Installing build dependencies: started
Installing build dependencies: finished with status ‘done’
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status ‘done’
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status ‘done’
Building wheels for collected packages: pillow
Building wheel for pillow (pyproject.toml): started
Building wheel for pillow (pyproject.toml): finished with status ‘error’
Failed to build pillow
File “C:\Users\robcl\AppData\Local\Temp\pip-build-env-3l8fhfiz\overlay\Lib\site-packages\setuptools\command\”, line 84, in run
File “C:\Users\robcl\AppData\Local\Temp\pip-build-env-3l8fhfiz\overlay\Lib\site-packages\setuptools_distutils\command\”, line 345, in run
File “”, line 811, in build_extensions
main.RequiredDependencyException: zlib

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "C:\Python39\lib\site-packages\pip\_vendor\pep517\in_process\", line 363, in <module>
    File "C:\Python39\lib\site-packages\pip\_vendor\pep517\in_process\", line 345, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "C:\Python39\lib\site-packages\pip\_vendor\pep517\in_process\", line 261, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
    File "C:\Users\robcl\AppData\Local\Temp\pip-install-osvzd6c9\pillow_aa355def229b4b5b850a94902d1d0d82\_custom_build\", line 53, in build_wheel
      return super().build_wheel(wheel_directory, config_settings, metadata_directory)
    File "C:\Users\robcl\AppData\Local\Temp\pip-build-env-3l8fhfiz\overlay\Lib\site-packages\setuptools\", line 416, in build_wheel
      return self._build_with_temp_dir(['bdist_wheel'], '.whl',
    File "C:\Users\robcl\AppData\Local\Temp\pip-build-env-3l8fhfiz\overlay\Lib\site-packages\setuptools\", line 401, in _build_with_temp_dir
    File "C:\Users\robcl\AppData\Local\Temp\pip-install-osvzd6c9\pillow_aa355def229b4b5b850a94902d1d0d82\_custom_build\", line 47, in run_setup
      return super().run_setup(setup_script)
    File "C:\Users\robcl\AppData\Local\Temp\pip-build-env-3l8fhfiz\overlay\Lib\site-packages\setuptools\", line 338, in run_setup
      exec(code, locals())
    File "<string>", line 1005, in <module>

  The headers or library files could not be found for zlib,
  a required dependency when compiling Pillow from source.

  Please see the install instructions at:

  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pillow

I have tried this same upgrade before and run into a different error: it was complaining about a module being missing. I installed the module and got a different error. Some articles on the net suggested I install a different version of the same module. I did this and I think it made things better but the installation still failed. Sorry to be so utterly vague, but this was some time ago and I can’t remember the details. I also tried Python 10 with the same results.

Is wxpython meant to be compatible with Python 3.9 and later?

Thanks for any help.
Rob Cliffe

Yes, wxPython works fine with Python 3.9 on Windows. However, you’ll notice your error is about installing pillow, not wxPython. You could follow the instructions in the error message, or I suspect you can work around the problem by installing an older version of pillow. Try python -m pip install pillow == 9.5.0 and then install wxPython.

Thank you swt2c! That solved the problem (although I note that spaces are not allowed around the “==” in your pip command).
By the way, the module that pip used to complain about (not any more) was attrdict. Installing that, or attrdict3, didn’t solve the problem (at the time).
Thanks again.

Yes, I’m aware of the problems with attrdict. Those mostly come into play when there is not a suitable wxPython wheel available and wxPython has to be compiled, which is a somewhat complicated process.