安装 pocketsphinx python 模块:命令 'swig.exe' 失败

Installing pocketsphinx python module: command 'swig.exe' failed

我得到了这样的东西。谁能告诉我如何解决这个问题。

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\

您尝试使用 pip 安装 pocketsphinx,这将下载并编译此模块。它需要一些编译工具,如 swig.

另一个解决方案是安装 pocketsphinx 的二进制版本。您可以下载二进制版本 here。您必须 select 与您的安装相关的正确版本。

要确定您必须下载哪一个,您可以 运行 以下命令,它将告诉您您需要哪个版本以及您 运行 32 位还是 64 位 python 口译员。

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

以下是您下载正确版本后可以输入的一些命令

"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

为了解决这个问题,我在撰写此答案时下载了 swig for windows,它是 3.0.12

For the latest swig windows version follow this link

  1. 复制 swig.exe 到 python 安装文件夹(例如 C:/python27)

  2. 打开 swigwin-3.0.12/Lib 文件夹并将所有 *.swg 文件复制到 C:/python27/Lib 或等效的 python 路径

  3. 打开swigwin-3.0.12/Lib/python并将所有文件复制到C:/python27/Lib

  4. 打开swigwin-3.0.12/Lib文件夹并将typemaps文件夹复制到C:/python27/Lib

(同时确保您安装了适用于 Python 的 Microsoft Visual C++ 编译器)

这些步骤对我有用。

我也遇到了同样的错误,在 ubuntu 16.04 中安装时,我执行了以下命令:

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

sudo pip install pocketsphinx

来源:pocketsphinx-python

无需将 Swig 文件复制到 Python 文件夹,您只需将 Swig 的位置添加到环境变量即可:

  1. Ctrl+S
  2. 键入 env 并按 Enter
  3. 双击 Path
  4. path-to-Swig 添加到最后一个空行
  5. 单击 OK 并重新启动您的 PC

很少有命令集可以解决这个问题。只需执行它们:

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

如果您正在使用 anaconda navigator。
就去环境吧。
搜索 swig,你的包就会显示出来。 Select 包并点击应用按钮。 还会给出其他依赖的提示列表,需要用swig安装。
所以只 select 全部然后点击应用按钮。
所有依赖项都将安装在 anaconda 的根目录中。

这对我有用,希望对您有所帮助。

conda install swig
pip install pocketsphinx

我不想做其他人建议的所有设置,所以我尝试了这个并且成功了。 不过,这可能仅在您使用 Anaconada 时才有效。

对我有用的是从 conda 安装 swing 和

conda install swing

如果安装搜索安装位置

where swing

然后将该路径添加到您的环境变量

对于遇到类似问题的 mac 用户,当前的 pip 安装框架似乎存在问题。我关注 this thread 并使用了链接的解决方案。似乎不会很快 pip 修复。

请注意,在 运行 上述步骤之前,您必须 brew install swig - homebrew install link

pip install pipwin
python -m pipwin install pocketsphinx

也可以使用pipwin安装pocketsphinx