24

I'm getting something like this. Can anyone please tell me how to fix this.

C:\Users\krush\Documents\ML using Python>pip install pocketsphinx
Collecting pocketsphinx
  Using cached pocketsphinx-0.1.3.zip
Building wheels for collected packages: pocketsphinx
  Running setup.py bdist_wheel for pocketsphinx: started
  Running setup.py bdist_wheel for pocketsphinx: finished with status 'error'
  Complete output from command C:\Users\krush\Anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\krush\\AppData\\Local\\Temp\\pip-build-cns2i_wb\\pocketsphinx\\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 C:\Users\krush\AppData\Local\Temp\tmp3tyvnl9wpip-wheel- --python-tag cp36:
  running bdist_wheel
  running build_ext
  building 'sphinxbase._ad' extension
  swigging swig/sphinxbase/ad.i to swig/sphinxbase/ad_wrap.c
  swig.exe -python -modern -Ideps/sphinxbase/include -Ideps/sphinxbase/include/sphinxbase -Ideps/sphinxbase/include/win32 -Ideps/sphinxbase/swig -outdir sphinxbase -o swig/sphinxbase/ad_wrap.c swig/sphinxbase/ad.i
  error: command 'swig.exe' failed: No such file or directory

  ----------------------------------------
  Failed building wheel for pocketsphinx
  Running setup.py clean for pocketsphinx
Failed to build pocketsphinx
Installing collected packages: pocketsphinx
  Running setup.py install for pocketsphinx: started
    Running setup.py install for pocketsphinx: finished with status 'error'
    Complete output from command C:\Users\krush\Anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\krush\\AppData\\Local\\Temp\\pip-build-cns2i_wb\\pocketsphinx\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\krush\AppData\Local\Temp\pip-x5mxeczy-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build_ext
    building 'sphinxbase._ad' extension
    swigging swig/sphinxbase/ad.i to swig/sphinxbase/ad_wrap.c
    swig.exe -python -modern -Ideps/sphinxbase/include -Ideps/sphinxbase/include/sphinxbase -Ideps/sphinxbase/include/win32 -Ideps/sphinxbase/swig -outdir sphinxbase -o swig/sphinxbase/ad_wrap.c swig/sphinxbase/ad.i
    error: command 'swig.exe' failed: No such file or directory

    ----------------------------------------
Command "C:\Users\krush\Anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\krush\\AppData\\Local\\Temp\\pip-build-cns2i_wb\\pocketsphinx\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\krush\AppData\Local\Temp\pip-x5mxeczy-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\krush\AppData\Local\Temp\pip-build-cns2i_wb\pocketsphinx\
Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
Krushi Raj
  • 528
  • 1
  • 4
  • 14
  • Possible duplicate of [Swig not found when installing pocketsphinx Python](https://stackoverflow.com/questions/33745389/swig-not-found-when-installing-pocketsphinx-python) – Nikolay Shmyrev Jun 12 '17 at 18:45
  • **Google Colab** users might want to look [this](https://stackoverflow.com/a/54124548/5320982) answer – Rex5 Jun 27 '19 at 08:48

12 Answers12

34

To fix the problem, I downloaded swig for windows at the time of writing this answer it was 3.0.12

For the latest swig windows version follow this link

  1. Copy swig.exe to the python installation folder (for ex C:/python27)

  2. Open the swigwin-3.0.12/Lib folder and copy all *.swg files to the C:/python27/Lib or equivalent python path

  3. Open swigwin-3.0.12/Lib/python and copy all the files to C:/python27/Lib

  4. Open the swigwin-3.0.12/Lib folder and copy over the typemaps folder to C:/python27/Lib

(Also make sure you have Microsoft Visual C++ Compiler for Python installed)

These steps worked for me.

Jay Shenawy
  • 953
  • 1
  • 12
  • 22
  • 12
    I also needed to copy the 'typemaps' folder to the C:/python27/Lib folder. – sawyermclane May 25 '18 at 20:19
  • 2
    I copied your .zip link for `swig for windows`, installed to a directory, added that directory to my environment variables PATH - re-opened a new terminal and ran "pip install PocketSphinx" and it succeeded this time. – Jordan Stefanelli Nov 07 '19 at 11:35
  • how do i fing swig for linux – Naveen Reddy Marthala Jan 20 '20 at 10:41
  • 1
    You can visit http://www.swig.org/download.html to get the latest version of swig for windows. – Qin Heyang Jan 27 '21 at 20:54
  • 1
    check out the correct answer using environment variables https://stackoverflow.com/a/52329457/2474348 – PythoNic Feb 08 '21 at 18:43
  • I get multiple errors `(1) : Error: Unable to find 'swig.swg'` , `SWIG\_m2crypto.i(30) : Error: Unable to find 'openssl\opensslv.h'` , `SWIG\_m2crypto.i(33) : Error: Unable to find 'openssl\safestack.h'` and many more – West Jan 06 '22 at 11:15
30
conda install swig
pip install pocketsphinx

I didn't want to do all that setup other people are suggesting so I tried this and it worked. This probably only works if you are using Anaconada though.

Jaideep Heer
  • 460
  • 4
  • 6
  • 1
    That worked. If you're a Windows user, make sure to run the Anaconda Prompt as administrator – Idhem Feb 04 '20 at 11:17
  • I am on Win10 and it says "'conda' is not recognized as an internal or external command, operable program or batch file." –  Aug 23 '20 at 10:33
  • 2
    this ought to be the accepted answer imo. less is more. – asparism Apr 17 '21 at 01:26
26

Instead of copying Swig files to the Python folder, you can simply add Swig`s location to the environment variables:

  1. Press Ctrl+S
  2. Type env and press Enter
  3. Double click on Path
  4. Add the path-to-Swig to the last blank line
  5. Click OK and restart your PC
W Barreto
  • 438
  • 4
  • 11
  • 1
    This is a very nice solution and better then the current accepted answer. – Stefan Jan 03 '21 at 16:26
  • 4
    Did you mean 1. [Windows-Key] + S ? and 2. Edit environment variables ? and 3. Press "Environment variables" before your 3 ? And according to https://superuser.com/questions/130029/refresh-environment-variable you can logout and login again instead of 5. Restart – PythoNic Feb 08 '21 at 18:51
  • 2
    I'm the author of the accepted answer and I agree this one is better – Jay Shenawy Apr 15 '21 at 22:22
  • 1
    You don't have to restart your PC on most of the cases, just restarting the command line worked here. – rockikz May 13 '21 at 17:40
10

You try to install pocketsphinx with pip, that will download and compile this module. It requires some compiling tool like swig.

Another solution is to install a binary version of pocketsphinx. You can download a binary version here. You have to select the correct version with respect to your installation.

To determine which one you have to download, you can run the following commands, that will tell you which version you require and whether you run a 32 or 64 bit python interpreter.

"C:\Users\krush\Anaconda3\python.exe" --version
"C:\Users\krush\Anaconda3\python.exe" -c "import struct;print(struct.calcsize('P') * 8)"

Below are some commands that you may enter once you have downloaded the correct version

"C:\Users\krush\Anaconda3\python.exe" -m pip install pocketsphinx‑0.1.3‑cp35‑cp35m‑win32.whl
"C:\Users\krush\Anaconda3\python.exe" -m pip install pocketsphinx‑0.1.3‑cp36‑cp36m‑win_amd64.whl
Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
6

I was also getting same error, while installing in ubuntu 16.04, I executed following commands:

sudo apt-get install -y python python-dev python-pip build-essential swig git libpulse-dev

sudo pip install pocketsphinx

source: pocketsphinx-python

Ramesh Kumar
  • 1,508
  • 15
  • 16
2

In case you are working on anaconda navigator.
Just go to environment.
Search swig, your package will be displayed. Select the package and click on apply button. It will also give a prompt list of other dependencies, which need to be installed with swig.
So just select all and click on apply button.
All the dependencies will be installed in your root directory of anaconda.

This worked for me, hope it helps.

ambar mishra
  • 64
  • 1
  • 5
1

There are few set of commands to resolve this. Just execute them:

sudo apt-get install -y python3 python3-dev python3-pip build-essential swig git libpulse-dev

sudo apt-get install libasound2-dev

sudo pip install pocketsphinx
1

what works for me is installing swing from conda and

conda install swig

if installed search where it is installed

where swig

enter image description here

then add that path to your environment variable

torayeff
  • 9,296
  • 19
  • 69
  • 103
0

For mac users getting similar issues, there seems to be a problem with the current pip install framework. I followed this thread and used the solution linked. It doesn't seem like there will be a pip fix anytime soon.

Note you'll have to brew install swig before running the above steps - homebrew install link.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Michael Berk
  • 705
  • 7
  • 23
0
pip install pipwin
python -m pipwin install pocketsphinx

You can also use pipwin to install pocketsphinx.

brandav
  • 623
  • 4
  • 10
0

For a purely pip-based fix (may or not work depending on your exact issue/system):

pip install swig
pip install pocketsphinx
pip freeze > requirements.txt

Fixed the issue simply for me. With pip freeze, you're likely to not have the issue again if cloning the project in another system (since swig will be installed just with pip install -r requirements.txt)

This is the kind of things for which it becomes REALLY worthwhile to look into using virtualenv or similar, instead of polluting (and endlessly re-configuring) your system.

logicOnAbstractions
  • 2,178
  • 4
  • 25
  • 37
0

I know I am late, but what worked for me was to download the pre-built wheel file and install it manually (tested on Windows. I am pretty sure it will only work on Windows).

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pocketsphinx

Just grab the right one (cp39 = python 3.9). When it finishes downloading, navigate to your downloads folder in cmd, and issue the following command:

pip install pocketsphinx-0.1.15-cp39-cp39-win_amd64.whl

NOTE: Change pocketsphinx-0.1.15-cp39-cp39-win_amd64.whl to the name of the whl file you downloaded. I grabbed this one because I use Python 3.9 64bit version.

CPSuperstore
  • 633
  • 10
  • 18