How to Fix ERROR: Failed building wheel for PocketSphinx

PocketSphinx is a lightweight speech recognition engine developed by Carnegie Mellon University. It is widely used for various applications, but users often encounter the “Failed building wheel for PocketSphinx” error during installation. This error typically occurs when trying to install the PocketSphinx Python package using tools like pip. In this article, we will explore common causes of this error and provide step-by-step solutions with examples to help you resolve it.

1. How to Reproduce The ERROR: Failed building wheel for PocketSphinx.

  1. When I run the command pip install PocketSphinx in a terminal to install the Python PocketSphinx module, I encounter the error message like Failed building wheel for PocketSphinx.
  2. elow is the detailed error messages.
    (MyPython) PS C:\Users\Zhao Song> pip install PocketSphinx
    Defaulting to user installation because normal site-packages is not writeable
    Collecting PocketSphinx
      Using cached pocketsphinx-5.0.2.tar.gz (34.2 MB)
      Installing build dependencies ... done
      Getting requirements to build wheel ... done
      Preparing metadata (pyproject.toml) ... done
    Collecting sounddevice (from PocketSphinx)
      Using cached sounddevice-0.4.6-py3-none-win_amd64.whl (199 kB)
    Requirement already satisfied: CFFI>=1.0 in c:\users\zhao song\appdata\roaming\python\python39\site-packages (from sounddevice->PocketSphinx) (1.16.0)
    Requirement already satisfied: pycparser in c:\users\zhao song\appdata\roaming\python\python39\site-packages (from CFFI>=1.0->sounddevice->PocketSphinx) (2.21)
    Building wheels for collected packages: PocketSphinx
      Building wheel for PocketSphinx (pyproject.toml) ... error
      error: subprocess-exited-with-error
    
      × Building wheel for PocketSphinx (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> [383 lines of output]
    
    ......
    ......
          -- Trying 'NMake Makefiles (Visual Studio 15 2017 x64 v141)' generator - failure
          --------------------------------------------------------------------------------
    
                          ********************************************************************************
                          scikit-build could not get a working generator for your system. Aborting build.
    
                          Building windows wheels for Python 3.9 requires Microsoft Visual Studio 2022.
          Get it with "Visual Studio 2017":
    
            https://visualstudio.microsoft.com/vs/
    
          Or with "Visual Studio 2019":
    
              https://visualstudio.microsoft.com/vs/
    
          Or with "Visual Studio 2022":
    
              https://visualstudio.microsoft.com/vs/
    
                          ********************************************************************************
          [end of output]
    
      note: This error originates from a subprocess, and is likely not a problem with pip.
      ERROR: Failed building wheel for PocketSphinx
    Failed to build PocketSphinx
    ERROR: Could not build wheels for PocketSphinx, which is required to install pyproject.toml-based projects

2. How to Fix The ERROR: Failed building wheel for PocketSphinx.

  1. To fix this issue is also very easy, you should go to the URL https://www.lfd.uci.edu/~gohlke/pythonlibs/#pocketsphinx to find and download the related PocketSphinx wheel file.
  2. For example, for Python 3.9, you should download the file pocketsphinx‑0.1.15‑cp39‑cp39‑win_amd64.whl.
  3. After download it, go to the file saved folder and run the command pip install pocketsphinx‑0.1.15‑cp39‑cp39‑win_amd64.whl.
    (MyPython) PS D:\WorkSpace\Work\python-courses\python-speech-recognition> pip install .\pocketsphinx-0.1.15-cp39-cp39-win_amd64.whl
    Defaulting to user installation because normal site-packages is not writeable
    Processing d:\workspace\work\python-courses\python-speech-recognition\pocketsphinx-0.1.15-cp39-cp39-win_amd64.whl
    Installing collected packages: pocketsphinx
    Successfully installed pocketsphinx-0.1.15
  4. If you see the above success message, that means the Python module has been installed successfully.
  5. You can run the command pip show pocketsphinx to confirm that the PocketSphinx module has been installed in your Python environment.
    (MyPython) PS D:\WorkSpace\Work\python-courses\python-speech-recognition> pip show pocketsphinx
    Name: pocketsphinx
    Version: 0.1.15
    Summary: Python interface to CMU Sphinxbase and Pocketsphinx libraries
    Home-page: https://github.com/bambocher/pocketsphinx-python
    Author: Dmitry Prazdnichnov
    Author-email: [email protected]
    License: BSD
    Location: c:\users\zhao song\appdata\roaming\python\python39\site-packages
    Requires:
    Required-by:

3. Conclusion.

  1. In this article, we delved into the common issue of encountering the “Failed building wheel for PocketSphinx” error during the installation of the PocketSphinx Python package using pip. The error is often related to difficulties in building wheels for the PocketSphinx module, primarily on Windows systems, and may be associated with missing dependencies such as Microsoft Visual Studio 2022.
  2. The error messages and steps to reproduce the issue were detailed, providing users with a clear understanding of the problem. Additionally, the article presented a straightforward solution for resolving the error. Users are directed to a specific URL where they can download the required PocketSphinx wheel file compatible with their Python version (e.g., pocketsphinx-0.1.15-cp39-cp39-win_amd64.whl). The installation process is then explained step by step, ensuring a seamless resolution.
  3. By following the provided solution, users can successfully install the PocketSphinx module and verify its installation using the “pip show pocketsphinx” command. This comprehensive guide aims to assist users in overcoming the common installation hurdle associated with PocketSphinx, ultimately enabling them to leverage this lightweight speech recognition engine for their Python applications.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.