简体   繁体   English

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

[英]Installing pocketsphinx python module: command 'swig.exe' failed

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\

To fix the problem, I downloaded swig for windows at the time of writing this answer it was 3.0.12为了解决这个问题,我在写这个答案的时候下载了 swig for windows ,它是 3.0.12

For the latest swig windows version follow this link对于最新的 swig windows 版本,请点击此链接

  1. Copy swig.exe to the python installation folder (for ex C:/python27)将 swig.exe 复制到 python 安装文件夹(例如 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打开swigwin-3.0.12/Lib文件夹并将所有*.swg文件复制到C:/python27/Lib或等效的 python 路径

  3. Open swigwin-3.0.12/Lib/python and copy all the files to C:/python27/Lib打开swigwin-3.0.12/Lib/python并将所有文件复制到C:/python27/Lib

  4. Open the swigwin-3.0.12/Lib folder and copy over the typemaps folder to C:/python27/Lib打开swigwin-3.0.12/Lib文件夹并将typemaps文件夹复制到C:/python27/Lib

(Also make sure you have Microsoft Visual C++ Compiler for Python installed) (还要确保您安装了 Microsoft Visual C++ Compiler for Python)

These steps worked for me.这些步骤对我有用。

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.不过,这可能仅在您使用 Anconada 时才有效。

Instead of copying Swig files to the Python folder, you can simply add Swig`s location to the environment variables:无需将 Swig 文件复制到 Python 文件夹,您只需将 Swig 的位置添加到环境变量中即可:

  1. Press Ctrl+SCtrl+S
  2. Type env and press Enter输入env并按Enter
  3. Double click on Path双击Path
  4. Add the path-to-Swig to the last blank lineSwig 的路径添加到最后一个空白行
  5. Click OK and restart your PC单击OK并重新启动您的 PC

You try to install pocketsphinx with pip , that will download and compile this module.您尝试使用pip安装pocketsphinx ,它将下载并编译此模块。 It requires some compiling tool like swig .它需要一些编译工具,如swig

Another solution is to install a binary version of pocketsphinx .另一种解决方案是安装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.要确定您必须下载哪一个,您可以运行以下命令,这将告诉您您需要哪个版本以及您运行的是 32 位还是 64 位 python 解释器。

"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

I was also getting same error, while installing in ubuntu 16.04, I executed following commands:我也遇到了同样的错误,在 ubuntu 16.04 中安装时,我执行了以下命令:

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

sudo pip install pocketsphinx

source: pocketsphinx-python来源: pocketsphinx-python

In case you are working on anaconda navigator.如果您正在使用 anaconda 导航器。
Just go to environment.就去环境吧。
Search swig, your package will be displayed.搜索 swig,就会显示你的包。 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.它还会给出其他依赖项的提示列表,这些依赖项需要使用 swig 安装。
So just select all and click on apply button.所以只需全选并单击应用按钮。
All the dependencies will be installed in your root directory of anaconda.所有依赖项都将安装在 anaconda 的根目录中。

This worked for me, hope it helps.这对我有用,希望它有所帮助。

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

what works for me is installing swing from conda and对我有用的是从 conda 安装 swing 和

conda install swig

if installed search where it is installed如果安装搜索它的安装位置

where swig

在此处输入图像描述

then add that path to your environment variable然后将该路径添加到您的环境变量

For mac users getting similar issues, there seems to be a problem with the current pip install framework.对于遇到类似问题的 mac 用户,当前的pip安装框架似乎存在问题。 I followed this thread and used the solution linked.我关注了这个线程并使用了链接的解决方案。 It doesn't seem like there will be a pip fix anytime soon.似乎不会很快有一个pip修复。

Note you'll have to brew install swig before running the above steps - homebrew install link .请注意,在运行上述步骤之前,您必须brew install swig - homebrew install link

pip install pipwin
python -m pipwin install pocketsphinx

You can also use pipwin to install pocketsphinx.你也可以使用 pipwin 来安装 pocketsphinx。

For a purely pip-based fix (may or not work depending on your exact issue/system):对于纯粹基于 pip 的修复(取决于您的确切问题/系统可能会或不会起作用):

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 )使用 pip freeze,如果在另一个系统中克隆项目,您可能不会再遇到问题(因为 swig 将仅使用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.这是真正值得研究使用 virtualenv 或类似的东西,而不是污染(和无休止地重新配置)您的系统的事情。

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).我知道我迟到了,但对我有用的是下载预先构建的轮文件并手动安装(在 Windows 上测试。我很确定它只能在 Windows 上运行)。

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

Just grab the right one (cp39 = python 3.9).只要抓住右边的(cp39 = python 3.9)。 When it finishes downloading, navigate to your downloads folder in cmd, and issue the following command:下载完成后,导航到 cmd 中的下载文件夹,然后发出以下命令:

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.注意pocketsphinx-0.1.15-cp39-cp39-win_amd64.whl更改为您下载的 whl 文件的名称。 I grabbed this one because I use Python 3.9 64bit version.我抓住了这个,因为我使用的是 Python 3.9 64 位版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM