0

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

BUFFER_SIZE = 1024
REC_SECONDS = 5
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
print('Recording...')
data_frames = []
for f in range(0, RATE/BUFFER_SIZE * REC_SECONDS):
    data = stream.read(BUFFER_SIZE)
    data_frames.append(data)
print('Finished recording...')
stream.stop_stream()
stream.close()
pa.terminate()
  • 1
    Doesn't the post you copied the code from mention where to get utils? – joan Jan 26 '15 at 16:40
  • Which version of python are you running this with? – Steve Robillard Jan 26 '15 at 16:46
  • @SteveRobillard python2.7 – Fahadkalis Jan 26 '15 at 16:48
4

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 Jan 26 '15 at 19:24
  • check your current folder. the full path I believe is included in the error message. – Steve Robillard Jan 26 '15 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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