I am trying to follow along with a project written by Mike Smales - "Sound Classification using Deep Learning". In there, the author wrote a helper file called wavfilehelper.py:

wavehelper.py Code

import struct

class WavFileHelper():
    def read_file_properties(self, filename):

        wave_file = open(filename,"rb")
        riff = wave_file.read(12)
        fmt = wave_file.read(36)
        num_channels_string = fmt[10:12]
        num_channels = struct.unpack('<H', num_channels_string)[0]

        sample_rate_string = fmt[12:16]
        sample_rate = struct.unpack("<I",sample_rate_string)[0]
        bit_depth_string = fmt[22:24]
        bit_depth = struct.unpack("<H",bit_depth_string)[0]

        return (num_channels, sample_rate, bit_depth)

In his main program he calls the helper file like this:

from helpers.wavfilehelper import WavFileHelper

wavfilehelper = WavFileHelper()

However, when I run this block of code in PyCharm, it complains "ModuleNotFoundError: No module named 'helpers.wavfilehelper'"...how can I get this helper file to work in the PyCharm environment? Do I have to put the wavehelper.py file in a special folder to be called?

Any help will be greatly appreciated!


You've undoubtedly solved or worked-around this issue by now, but "helpers" or "utilities" or "UDFs" that get called like this need to exist in a folder within your project that contains a file called __init__.py. You can read up on how to structure your Python project from sites like this. See my project as an example: main.py does all the hard work and refers to helpers like you've shown above in the utils directory. See that special file I mentioned? That's the key to being able to import successfully.

Python Project Snapshot


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.