Python module ImportError: No module named pocketsphinx

Came across the error while experimenting with pocketsphinx – CMU Speech Recognition Kit.

Modules already installed by package manager:
python-pocketsphinx
pocketsphinx-hmm-wsj1
pocketsphinx-lm-wsj

Python shell is able to locate libs

help(‘pocketsphinx’) & dir(‘pocketsphinx’) works fine on the python shell, but importing it in the external script blows up with the below error:

Traceback (most recent call last):
 File "pythonPocketSphinxTest2.py", line 6, in < module >
 import pocketsphinx
 ImportError: No module named pocketsphinx

Quick fix:
The system is not able to find the python libs, just provide PYTHONPATH to system path.

vi ~/.bashrc
Add below lines:

export PYTHONPATH=/usr/lib/pymodules/python2.7 
export PATH=$PATH:$PYTHONPATH

Save and exit.
source ~/.bashrc

Thats It. We are done here. Cheers.

Note: Add the PYTHONPATH accordingly as where your python is present.

Yash Sharma is a Big Data & Machine Learning Engineer, A newbie OpenSource contributor, Plays guitar and enjoys teaching as part time hobby.
Talk to Yash about Distributed Systems and Data platform designs.

2 thoughts on “Python module ImportError: No module named pocketsphinx

Leave a Reply

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