如何在PyCharm中使用帮助文件 [英] How to use helper files in PyCharm

查看:108
本文介绍了如何在PyCharm中使用帮助文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试跟Mike编写的项目一起进行Smales-使用深度学习进行声音分类" .在其中,作者编写了一个名为wavfilehelper.py的帮助文件:

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代码

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()

但是,当我在PyCharm中运行此代码块时,它抱怨"ModuleNotFoundError:没有名为'helpers.wavfilehelper'的模块" ...如何获得该帮助文件在PyCharm环境中工作?我是否必须将 wavehelper.py 文件放在要调用的特殊文件夹中?

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?

任何帮助将不胜感激!

推荐答案

重要的是要查看(并在您的问题中引用)实际的错误消息!在这种情况下,哪一行是错误的?它不是实例化行,而是导入-Python无法(使用其系统路径)在您的计算机上找到该模块.

It is important to look at (and quote in your question) the actual error messages! In this case, which line is in-error? It is not the instantiation line, but the import - Python is unable to find the module on your machine (using its system paths).

在本文的早期,作者讨论了从GitHub下载文件(到您的计算机)的问题.您遵循了这一步骤吗?

Earlier in the article, the author talks about downloading his files from GitHub (to your machine). Did you follow that step?

Web.Ref:有关解决此问题的更多信息错误

这篇关于如何在PyCharm中使用帮助文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆