プログラミング・IT・英語・数学とか

英検1級、TOEIC満点(990点)、セキュリティスペシャリスト、DBスペシャリスト、ネットワークスペシャリスト。英語とITとか。いろいろ試してみたことを書いていきます

pip install --upgrade pocketsphinx が失敗するときの対応方法

現象

こんな感じのエラーメッセージが出る。

・・・省略・・・
deps/sphinxbase/src/libsphinxad/ad_alsa.c:76:28: fatal error: alsa/asoundlib.h: そのようなファイルやディレクトリはありません
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/shohei/tmp/20190810/env/bin/python3.5 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-__0ixsyy/pocketsphinx/setup.py'"'"'; __file__='"'"'/tmp/pip-install-__0ixsyy/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 /tmp/pip-record-w1j6dzl6/install-record.txt --single-version-externally-managed --compile --install-headers /home/shohei/tmp/20190810/env/include/site/python3.5/pocketsphinx Check the logs for full command output.

原因

インストールに必要な、いろいろなパッケージが入っていないために起こります。

対応方法

エラーとなったファイルがどのパッケージに入っているかを見つけて、エラーが出なくなるまでインストールし続ければ解決です。

# ファイルからパッケージを探すためにapt-fileをインストールします。インストール済みの場合はしなくてよいです。
sudo apt-get install apt-file
sudo apt-file update

# エラーメッセージから存在しないファイルを特定し探します。この例ではpulse/pulseaudio.hです。
sudo apt-file search pulse/pulseaudio.h

# 対象のパッケージをインストールします。
sudo apt-get install libpulse-dev