I am trying to run a program in python on RaspberryPi from stackexchange but getting an error

ImportError: No module named utils

Can you please help me resolve this issue?

import pyaudio, wave, utils

RATE = 44100
WAV_FILENAME = utils.generate_random_token()
FORMAT = pyaudio.paInt16

#init sound stream
pa = pyaudio.PyAudio()
stream = pa.open(
    format = FORMAT,
    input = True,
    channels = 1,
    rate = RATE,
    input_device_index = 7,
    frames_per_buffer = BUFFER_SIZE

#run recording
data_frames = []
for f in range(0, RATE/BUFFER_SIZE * REC_SECONDS):
    data = stream.read(BUFFER_SIZE)
print('Finished recording...')
  • 1
    Doesn't the post you copied the code from mention where to get utils?
    – joan
    Commented Jan 26, 2015 at 16:40
  • Which version of python are you running this with? Commented Jan 26, 2015 at 16:46
  • @SteveRobillard python2.7
    – Fahadkalis
    Commented Jan 26, 2015 at 16:48

1 Answer 1


First install pip:

sudo apt-get install python-pip

then install the utils module using pip:

pip install utils

If you get an error about permissions use sudo and rerun the above command:

sudo pip install utils

if you get an error about the README.txt file:

switch to the /build/utils directory and create an empty README.txt file:

touch README.txt

then rerun the pip install command.

  • do i know where is this /build/utils folder
    – Fahadkalis
    Commented Jan 26, 2015 at 19:24
  • check your current folder. the full path I believe is included in the error message. Commented Jan 26, 2015 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.