Can't install wxPython

Hello :slight_smile:
It’s my first time using python and downloading wxPython. I’m using Python 3.8 and pip3. When I type pip3 install wxPython, I get a really long error and I can’t figure out how to fix it. Anything help would be much appreciated, thank you so much!

Collecting wxPython
  Using cached wxPython-4.2.1.tar.gz (73.7 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting pillow (from wxPython)
  Using cached Pillow-9.5.0-cp37-cp37m-macosx_10_10_x86_64.whl (3.4 MB)
Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from wxPython) (1.16.0)
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from wxPython) (1.21.6)
Building wheels for collected packages: wxPython
  Building wheel for wxPython (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for wxPython (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [43 lines of output]
      running bdist_wheel
      running build
      Will build using: "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7"
      3.7.8 (v3.7.8:4b47a5b6ba, Jun 27 2020, 04:47:50)
      [Clang 6.0 (clang-600.0.57)]
      Python's architecture is 64bit
      cfg.VERSION: 4.2.1
      
      Running command: build
      Running command: build_wx
      wxWidgets build options: ['--wxpython', '--unicode', '--osx_cocoa', '--mac_universal_binary=default']
      Universal Capable: False
      Architectures:     x86_64
      Configure options: ['--enable-unicode', '--with-osx_cocoa', '--enable-universal_binary=x86_64', '--enable-sound', '--enable-graphics_ctx', '--enable-display', '--enable-geometry', '--enable-debug_flag', '--enable-optimise', '--disable-debugreport', '--enable-uiactionsim', '--enable-autoidman', '--with-macosx-version-min=10.10', '--with-libjpeg=builtin', '--with-libpng=builtin', '--with-libtiff=builtin', '--with-regex=builtin']
      /private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-1n6v2l0b/wxpython_63982331967342889ae83da74341073f/ext/wxWidgets/configure --enable-unicode --with-osx_cocoa --enable-universal_binary=x86_64 --enable-sound --enable-graphics_ctx --enable-display --enable-geometry --enable-debug_flag --enable-optimise --disable-debugreport --enable-uiactionsim --enable-autoidman --with-macosx-version-min=10.10 --with-libjpeg=builtin --with-libpng=builtin --with-libtiff=builtin --with-regex=builtin
      checking build system type... x86_64-apple-darwin21.5.0
      checking host system type... x86_64-apple-darwin21.5.0
      checking for toolkit... osx_cocoa
      checking for gcc... gcc
      checking whether the C compiler works... no
      configure: error: in `/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-1n6v2l0b/wxpython_63982331967342889ae83da74341073f/build/wxbld':
      configure: error: C compiler cannot create executables
      See `config.log' for more details
      Error running configure
      ERROR: failed building wxWidgets
      Traceback (most recent call last):
        File "build.py", line 1563, in cmd_build_wx
          wxbuild.main(wxDir(), build_options)
        File "/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-1n6v2l0b/wxpython_63982331967342889ae83da74341073f/buildtools/build_wxwidgets.py", line 380, in main
          "Error running configure")
        File "/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-1n6v2l0b/wxpython_63982331967342889ae83da74341073f/buildtools/build_wxwidgets.py", line 72, in exitIfError
          raise builder.BuildError(msg)
      buildtools.builder.BuildError: Error running configure
      Finished command: build_wx (0.853s)
      Finished command: build (0.853s)
      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.
      
      "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7" -u build.py build
      Command '"/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7" -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
Failed to build wxPython
ERROR: Could not build wheels for wxPython, which is required to install pyproject.toml-based projects

Hi Anusha, this pip install tries to build wxPython from the sources.
This is not the recommended way to get started.
What is your platform? Maybe binaries are available, but PyPi does only supply them for Windows and MacOS.

Ah, i see x86_64-apple-darwin21.
For Python 3.7 PyPI does not have current binaries any more: wxPython · PyPI

Can you live with the older revision 4.1.1?
This is available: wxPython · PyPI

I’m confused: You’re writing that you’re on Python 3.8, but your log shows 3.7.

If you have a 3.8, then do something like this:
python3.8 -mpip install wxpython
At least on other platforms the executable pip or pip3 often points to another binary than what you expect. Calling python with -mpip should solve this.

Hey, I checked the version and it said 3.8.8 for python.
I tried running the code you wrote above, and I apologize for the long text here -

python3.8 -mpip install wxpython
Collecting wxpython
  Using cached wxPython-4.2.1.tar.gz (73.7 MB)
Requirement already satisfied: pillow in /opt/anaconda3/lib/python3.8/site-packages (from wxpython) (8.2.0)
Requirement already satisfied: six in /opt/anaconda3/lib/python3.8/site-packages (from wxpython) (1.15.0)
Requirement already satisfied: numpy in /opt/anaconda3/lib/python3.8/site-packages (from wxpython) (1.20.1)
Building wheels for collected packages: wxpython
  Building wheel for wxpython (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /opt/anaconda3/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/setup.py'"'"'; __file__='"'"'/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-wheel-6p4uae4f
       cwd: /private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/
  Complete output (43 lines):
  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.
  
  "/opt/anaconda3/bin/python3.8" -u build.py build
  Will build using: "/opt/anaconda3/bin/python3.8"
  3.8.8 (default, Apr 13 2021, 12:59:45)
  [Clang 10.0.0 ]
  Python's architecture is 64bit
  cfg.VERSION: 4.2.1
  
  Running command: build
  Running command: build_wx
  wxWidgets build options: ['--wxpython', '--unicode', '--osx_cocoa', '--mac_universal_binary=default']
  Universal Capable: False
  Architectures:     x86_64
  Configure options: ['--enable-unicode', '--with-osx_cocoa', '--enable-universal_binary=x86_64', '--enable-sound', '--enable-graphics_ctx', '--enable-display', '--enable-geometry', '--enable-debug_flag', '--enable-optimise', '--disable-debugreport', '--enable-uiactionsim', '--enable-autoidman', '--with-macosx-version-min=10.10', '--with-libjpeg=builtin', '--with-libpng=builtin', '--with-libtiff=builtin', '--with-regex=builtin']
  /private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/ext/wxWidgets/configure --enable-unicode --with-osx_cocoa --enable-universal_binary=x86_64 --enable-sound --enable-graphics_ctx --enable-display --enable-geometry --enable-debug_flag --enable-optimise --disable-debugreport --enable-uiactionsim --enable-autoidman --with-macosx-version-min=10.10 --with-libjpeg=builtin --with-libpng=builtin --with-libtiff=builtin --with-regex=builtin
  checking build system type... x86_64-apple-darwin21.5.0
  checking host system type... x86_64-apple-darwin21.5.0
  checking for toolkit... osx_cocoa
  checking for gcc... gcc
  checking whether the C compiler works... no
  configure: error: in `/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/build/wxbld':
  configure: error: C compiler cannot create executables
  See `config.log' for more details
  Error running configure
  ERROR: failed building wxWidgets
  Traceback (most recent call last):
    File "build.py", line 1563, in cmd_build_wx
      wxbuild.main(wxDir(), build_options)
    File "/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/buildtools/build_wxwidgets.py", line 379, in main
      exitIfError(wxBuilder.configure(dir=wxRootDir, options=configure_opts),
    File "/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/buildtools/build_wxwidgets.py", line 72, in exitIfError
      raise builder.BuildError(msg)
  buildtools.builder.BuildError: Error running configure
  Finished command: build_wx (0.868s)
  Finished command: build (0.869s)
  Command '"/opt/anaconda3/bin/python3.8" -u build.py build' failed with exit code 1.
  ----------------------------------------
  ERROR: Failed building wheel for wxpython
  Running setup.py clean for wxpython
Failed to build wxpython
Installing collected packages: wxpython
    Running setup.py install for wxpython ... error
    ERROR: Command errored out with exit status 1:
     command: /opt/anaconda3/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/setup.py'"'"'; __file__='"'"'/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-record-a9caki6z/install-record.txt --single-version-externally-managed --compile --install-headers /opt/anaconda3/include/python3.8/wxpython
         cwd: /private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/
    Complete output (43 lines):
    running install
    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.
    
    "/opt/anaconda3/bin/python3.8" -u build.py build
    Will build using: "/opt/anaconda3/bin/python3.8"
    3.8.8 (default, Apr 13 2021, 12:59:45)
    [Clang 10.0.0 ]
    Python's architecture is 64bit
    cfg.VERSION: 4.2.1
    
    Running command: build
    Running command: build_wx
    wxWidgets build options: ['--wxpython', '--unicode', '--osx_cocoa', '--mac_universal_binary=default']
    Universal Capable: False
    Architectures:     x86_64
    Configure options: ['--enable-unicode', '--with-osx_cocoa', '--enable-universal_binary=x86_64', '--enable-sound', '--enable-graphics_ctx', '--enable-display', '--enable-geometry', '--enable-debug_flag', '--enable-optimise', '--disable-debugreport', '--enable-uiactionsim', '--enable-autoidman', '--with-macosx-version-min=10.10', '--with-libjpeg=builtin', '--with-libpng=builtin', '--with-libtiff=builtin', '--with-regex=builtin']
    /private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/ext/wxWidgets/configure --enable-unicode --with-osx_cocoa --enable-universal_binary=x86_64 --enable-sound --enable-graphics_ctx --enable-display --enable-geometry --enable-debug_flag --enable-optimise --disable-debugreport --enable-uiactionsim --enable-autoidman --with-macosx-version-min=10.10 --with-libjpeg=builtin --with-libpng=builtin --with-libtiff=builtin --with-regex=builtin
    checking build system type... x86_64-apple-darwin21.5.0
    checking host system type... x86_64-apple-darwin21.5.0
    checking for toolkit... osx_cocoa
    checking for gcc... gcc
    checking whether the C compiler works... no
    configure: error: in `/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/build/wxbld':
    configure: error: C compiler cannot create executables
    See `config.log' for more details
    Error running configure
    ERROR: failed building wxWidgets
    Traceback (most recent call last):
      File "build.py", line 1563, in cmd_build_wx
        wxbuild.main(wxDir(), build_options)
      File "/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/buildtools/build_wxwidgets.py", line 379, in main
        exitIfError(wxBuilder.configure(dir=wxRootDir, options=configure_opts),
      File "/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/buildtools/build_wxwidgets.py", line 72, in exitIfError
        raise builder.BuildError(msg)
    buildtools.builder.BuildError: Error running configure
    Finished command: build_wx (0.547s)
    Finished command: build (0.548s)
    Command '"/opt/anaconda3/bin/python3.8" -u build.py build' failed with exit code 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /opt/anaconda3/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/setup.py'"'"'; __file__='"'"'/private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-install-6y3hkw5e/wxpython_43932be50df44041aa80ea7084fae69c/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ks/jyd3_h812rsbkv9nmfrhb4km0000gn/T/pip-record-a9caki6z/install-record.txt --single-version-externally-managed --compile --install-headers /opt/anaconda3/include/python3.8/wxpython Check the logs for full command output.
(base) python --version
Python 3.8.8

I don’t have 3.8 on my MacOS VM, so I can’t reproduce why pip wants to use the source instead of a binary. My installation pre-dates the universal wheels for x86 and ARM.

Could you please try to purge the cache first with python3.8 -mpip cache purge

If that still fails, maybe download the .whl file from https://files.pythonhosted.org/packages/52/1e/d95b693c2f123b7bf5f816e4d0a390d5d3cdb88672bfb899b3d1bbb6887a/wxPython-4.2.1-cp38-cp38-macosx_11_0_universal2.whl

Then install it from that:
python3.8 -mpip install wxPython-4.2.1-cp38-cp38-macosx_11_0_universal2.whl
If that still fails, I don’t know a solution…

Alternatively, it seems you’re using Anaconda. That should have a package manager. I don’t remember the command line for this as I don’t like it…

Thank you for your help thus far! I tried clearing the cache, then running the script. Did not work.
I tried downloading the .whl file, but it gave me an error -

> ERROR: wxPython-4.2.1-cp38-cp38-macosx_11_0_universal2.whl is not a supported wheel on this platform.

OK, that might be the root cause. I don’t have experience with the universal wheels. Maybe Python 3.8 does not support it at all or your pip is too old.
You can upgrade pip using python3.8 -m pip install --upgrade pip

If that still fails, for the time being, you may try to use wxPython revision 4.1.1.
That seems to have a ‘classic’ wheel: wxPython · PyPI
You can install a specific version using ==:
python3.8 -mpip install wxPython==4.1.1
Good luck.