# Module not found for python file in plugin directory

**URL:** <https://discourse.beets.io/t/module-not-found-for-python-file-in-plugin-directory/1660>\
**Category:** Development\
**Created:** [January 12, 2021, 4:23pm UTC](https://discourse.beets.io/t/module-not-found-for-python-file-in-plugin-directory/1660 "2021-01-12T16:23:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phirestalker](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@phirestalker](https://discourse.beets.io/u/phirestalker)\
**Post date:** [January 12, 2021, 4:23pm UTC](https://discourse.beets.io/t/module-not-found-for-python-file-in-plugin-directory/1660/1 "2021-01-12T16:23:38Z")

</div>

I am writing a plugin and I wish to keep certain functions in a separate file. It is called utils.py and it is in the same directory (beetsplug) that the main plugin file is in. I use from utils import \* and I get the error module not found.

I am able to do this with a regular python program that also uses the utils.py file. For some reason, it does not work when importing from a beets plugin.

How can I import functions from the utils.py file in my plugin?

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [January 12, 2021, 4:38pm UTC](https://discourse.beets.io/t/module-not-found-for-python-file-in-plugin-directory/1660/2 "2021-01-12T16:38:49Z")

</div>

You’ll want to create a Python package (i.e., a directory with an ` __init__.py` in it). Like the `bpd` plugin included with beets, for instance:

> **[beetbox/beets](https://github.com/beetbox/beets/tree/master/beetsplug/bpd)**
>
> master/beetsplug/bpd

---

<div class="post-metadata">

**Author:** ![phirestalker](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@phirestalker](https://discourse.beets.io/u/phirestalker)\
**Post date:** [January 12, 2021, 8:30pm UTC](https://discourse.beets.io/t/module-not-found-for-python-file-in-plugin-directory/1660/3 "2021-01-12T20:30:23Z")

</div>

So, I just move all the functions into the ` __init__.py` file under the directory named utils?

EDIT: OK, I think I figured it out. I moved everything into the ` __init__.py` file inside utils folder inside beetsplug. Then, I put `from beetsplug import utils`

Now i do not get the error. I have not gotten far enough to know if I can access the functions yet.

---

<div class="post-metadata">

**Author:** ![halloleo](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@halloleo](https://discourse.beets.io/u/halloleo)\
**Post date:** [January 20, 2021, 4:09am UTC](https://discourse.beets.io/t/module-not-found-for-python-file-in-plugin-directory/1660/4 "2021-01-20T04:09:09Z")

</div>

Not that I’m an `beets` expert at all, but Python packages are generally named as the tool (here plugin) they represent. So, let’s say your plugin is called **`silence`**. Then you have two cases:

1. If you all the stuff for your plugin is just in one file only, then call the file `silence.py` and place it directly in the plugin dir. (That’s the situation for most beets plugins.)

2. If you have stuff in multiple files, create a directory with the name `silence` in the plugin dir and place all your files (here `utils.py` and your main file as ` __init__.py`) _under your directory_ `silence`.

Hope this helps!
