# How to get the package directory?

**URL:** <https://forum.modular.com/t/how-to-get-the-package-directory/2268>\
**Category:** Mojo\
**Created:** [September 13, 2025, 11:15pm UTC](https://forum.modular.com/t/how-to-get-the-package-directory/2268 "2025-09-13T23:15:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cahya](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/cahya/32/752_2.png) [@cahya](https://forum.modular.com/u/cahya)\
**Post date:** [September 13, 2025, 11:15pm UTC](https://forum.modular.com/t/how-to-get-the-package-directory/2268/1 "2025-09-13T23:15:35Z")

</div>

Hi,

I need to read a file that I included in my package, so I have to get the path to the package directory, how can I do it? I tried to use Path(\__file_\_), but it seems mojo doesn’t know \__file_\_, which is python specific. This is the error message:  
error: use of unknown declaration ‘\__file_\_’.

---

<div class="post-metadata">

**Author:** ![miktavarez](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/miktavarez/32/446_2.png) [@miktavarez](https://forum.modular.com/u/miktavarez)\
**Post date:** [September 14, 2025, 3:29pm UTC](https://forum.modular.com/t/how-to-get-the-package-directory/2268/2 "2025-09-14T15:29:42Z")

</div>

Maybe this is what you’re looking for? It’s at least it’s relative to the current file, so you can navigate from there: [modular/mojo/stdlib/stdlib/pathlib/path.mojo at main · modular/modular · GitHub](https://github.com/modular/modular/blob/main/mojo/stdlib/stdlib/pathlib/path.mojo#L48C4-L48C24)

---

<div class="post-metadata">

**Author:** ![owenhilyard](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/owenhilyard/32/41_2.png) [@owenhilyard](https://forum.modular.com/u/owenhilyard)\
**Post date:** [September 14, 2025, 6:45pm UTC](https://forum.modular.com/t/how-to-get-the-package-directory/2268/3 "2025-09-14T18:45:22Z")

</div>

Mojo very aggressively blurs what ` __file__ ` is, since it could be referring to the directory where the source file lived or the directory where the `.mojopkg` file lives.

What kind of data is included in that file? You might be able to shove it into mojo code as serialized data and not deal with it.

---

<div class="post-metadata">

**Author:** ![cahya](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/cahya/32/752_2.png) [@cahya](https://forum.modular.com/u/cahya)\
**Post date:** [September 14, 2025, 8:38pm UTC](https://forum.modular.com/t/how-to-get-the-package-directory/2268/4 "2025-09-14T20:38:39Z")

</div>

Thanks, I tried it, unfortunately when I built a package, and I move the package to different directory, the “\_dir\_of\_current\_file” function will still return the original package directory when the package was built, not the new directory to where I move it.

---

<div class="post-metadata">

**Author:** ![cahya](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/cahya/32/752_2.png) [@cahya](https://forum.modular.com/u/cahya)\
**Post date:** [September 15, 2025, 7:46am UTC](https://forum.modular.com/t/how-to-get-the-package-directory/2268/5 "2025-09-15T07:46:11Z")

</div>

I am trying to rewrite the RWKV Tokenizer from Rust to Mojo. The tokenizer includes the vocabulary file in its package, it will be read when the tokenizer is instantiated.

This is the early working version of the RWKV Tokenizer in Mojo [GitHub - cahya-wirawan/rwkv-tokenizer-mojo](https://github.com/cahya-wirawan/rwkv-tokenizer-mojo) . It’s my first mojo code, so bear with me 🙂

Btw, is there a Mojo package repository like [pypi.org](http://pypi.org) or [crates.io](http://crates.io) ?

---

<div class="post-metadata">

**Author:** ![owenhilyard](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/owenhilyard/32/41_2.png) [@owenhilyard](https://forum.modular.com/u/owenhilyard)\
**Post date:** [September 15, 2025, 12:49pm UTC](https://forum.modular.com/t/how-to-get-the-package-directory/2268/6 "2025-09-15T12:49:56Z")

</div>

For tokenizers, I would write a script which converts things to Mojo dictionary literals and throws them in a file. That way you avoid file IO and the tokenizer can run on GPUs.

Right now we have [https://github.com/modular/modular-community](https://github.com/modular/modular-community) as a repo since we don’t have a lot of libraries. We’ll need to look at whether pypi can work for Mojo since it has issues with GPU support being indicated and doesn’t let users include metadata about required driver versions or other info.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [March 14, 2026, 12:50pm UTC](https://forum.modular.com/t/how-to-get-the-package-directory/2268/7 "2026-03-14T12:50:54Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
