Why do I get a subprocess error when installing cx_Freeze?

Question:

I am using the pip install cx_Freeze command, but I get a subprocess error. Why does it happen?
Note: My system is Windows 11 and my Python version is 3.11.1.
Command Output:

C:Users<user>>pip install cx_Freeze
Collecting cx_Freeze
  Using cached cx_Freeze-6.13.1.tar.gz (1.5 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: packaging>=21.0 in c:users<user> appdatalocalprogramspythonpython311libsite-packages (from cx_Freeze) (23.0)
Requirement already satisfied: setuptools<66,>=59.0.1 in c:users<user>appdatalocalprogramspythonpython311libsite-packages (from cx_Freeze) (65.5.0)
Requirement already satisfied: lief>=0.12.0 in c:users<user>appdatalocalprogramspythonpython311libsite-packages (from cx_Freeze) (0.12.3)
Building wheels for collected packages: cx_Freeze
  Building wheel for cx_Freeze (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for cx_Freeze (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [84 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating buildlib.win-amd64-cpython-311
      creating buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezecli.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezecommon.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezedarwintools.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezedist.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezeexception.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezeexecutable.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezefinder.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezefreezer.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezemodule.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezeparser.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezesandbox.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezesetupwriter.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezewinmsvcr.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freezewinversioninfo.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freeze_compat.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freeze__init__.py -> buildlib.win-amd64-cpython-311cx_Freeze
      copying cx_Freeze__main__.py -> buildlib.win-amd64-cpython-311cx_Freeze
      creating buildlib.win-amd64-cpython-311cx_Freezebases
      copying cx_Freezebases__init__.py -> buildlib.win-amd64-cpython-311cx_Freezebases
      creating buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommandbdist_mac.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommandbdist_msi.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommandbdist_rpm.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommandbuild.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommandbuild_exe.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommandinstall.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommandinstall_exe.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommand_bdist_msi.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommand_pydialog.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      copying cx_Freezecommand__init__.py -> buildlib.win-amd64-cpython-311cx_Freezecommand
      creating buildlib.win-amd64-cpython-311cx_Freezehooks
      copying cx_Freezehookscrypto.py -> buildlib.win-amd64-cpython-311cx_Freezehooks
      copying cx_Freezehookscv2.py -> buildlib.win-amd64-cpython-311cx_Freezehooks
      copying cx_Freezehooksexclude.py -> buildlib.win-amd64-cpython-311cx_Freezehooks
      copying cx_Freezehooksnumpy.py -> buildlib.win-amd64-cpython-311cx_Freezehooks
      copying cx_Freezehooksscipy.py -> buildlib.win-amd64-cpython-311cx_Freezehooks
      copying cx_Freezehooks_qthooks.py -> buildlib.win-amd64-cpython-311cx_Freezehooks
      copying cx_Freezehooks__init__.py -> buildlib.win-amd64-cpython-311cx_Freezehooks
      creating buildlib.win-amd64-cpython-311cx_Freezeinitscripts
      copying cx_Freezeinitscriptsconsole.py -> buildlib.win-amd64-cpython-311cx_Freezeinitscripts
      copying cx_Freezeinitscriptsconsolesetlibpath.py -> buildlib.win-amd64-cpython-311cx_Freezeinitscripts
      copying cx_Freezeinitscriptssharedlib.py -> buildlib.win-amd64-cpython-311cx_Freezeinitscripts
      copying cx_Freezeinitscriptssharedlibsource.py -> buildlib.win-amd64-cpython-311cx_Freezeinitscripts
      copying cx_Freezeinitscripts__init__.py -> buildlib.win-amd64-cpython-311cx_Freezeinitscripts
      copying cx_Freezeinitscripts__startup__.py -> buildlib.win-amd64-cpython-311cx_Freezeinitscripts
      creating buildlib.win-amd64-cpython-311cx_Freezehookspyqt5
      copying cx_Freezehookspyqt5add_library.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyqt5
      copying cx_Freezehookspyqt5debug.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyqt5
      copying cx_Freezehookspyqt5__init__.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyqt5
      creating buildlib.win-amd64-cpython-311cx_Freezehookspyqt6
      copying cx_Freezehookspyqt6debug.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyqt6
      copying cx_Freezehookspyqt6__init__.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyqt6
      creating buildlib.win-amd64-cpython-311cx_Freezehookspyside2
      copying cx_Freezehookspyside2debug.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyside2
      copying cx_Freezehookspyside2resource.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyside2
      copying cx_Freezehookspyside2__init__.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyside2
      creating buildlib.win-amd64-cpython-311cx_Freezehookspyside6
      copying cx_Freezehookspyside6debug.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyside6
      copying cx_Freezehookspyside6resource.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyside6
      copying cx_Freezehookspyside6__init__.py -> buildlib.win-amd64-cpython-311cx_Freezehookspyside6
      running egg_info
      writing cx_Freeze.egg-infoPKG-INFO
      writing dependency_links to cx_Freeze.egg-infodependency_links.txt
      writing entry points to cx_Freeze.egg-infoentry_points.txt
      writing requirements to cx_Freeze.egg-inforequires.txt
      writing top-level names to cx_Freeze.egg-infotop_level.txt
      reading manifest file 'cx_Freeze.egg-infoSOURCES.txt'
      reading manifest template 'MANIFEST.in'
      adding license file 'doc/src/license.rst'
      writing manifest file 'cx_Freeze.egg-infoSOURCES.txt'
      copying cx_Freezehookspyside2qt.conf -> buildlib.win-amd64-cpython-311cx_Freezehookspyside2
      copying cx_Freezehookspyside2resource.qrc -> buildlib.win-amd64-cpython-311cx_Freezehookspyside2
      copying cx_Freezehookspyside2resource.sh -> buildlib.win-amd64-cpython-311cx_Freezehookspyside2
      copying cx_Freezehookspyside6qt.conf -> buildlib.win-amd64-cpython-311cx_Freezehookspyside6
      copying cx_Freezehookspyside6resource.qrc -> buildlib.win-amd64-cpython-311cx_Freezehookspyside6
      copying cx_Freezehookspyside6resource.sh -> buildlib.win-amd64-cpython-311cx_Freezehookspyside6
      running build_ext
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cx_Freeze
Failed to build cx_Freeze
ERROR: Could not build wheels for cx_Freeze, which is required to install pyproject.toml-based projects
Asked By: Dat1_

||

Answers:

From the error message: "error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/"

cx_freeze requires a c-compiler: https://cx-freeze.readthedocs.io/en/latest/installation.html#python-requirements

Answered By: Tzane
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.