M
Modular2mo ago
bunny

import_path

This post is not a Q, but rather an A for peeps to search out. I'm abusing this Questions forum as a knowledge base, so to say. In this vid, Shashank refs that the file ~/.modular/modular.cfg's setting mojo.import_path can take comma-sep values to identify multiple import paths. The default value is something like:
[mojo]
import_path = /Users/***/.modular/pkg/packages.modular.com_mojo/lib/mojo
[mojo]
import_path = /Users/***/.modular/pkg/packages.modular.com_mojo/lib/mojo
That path contains a bunch of .mojopkg files (like stdlib.mojopkg, algo, math, etc). As the video says, you can add another path, like this:
[mojo]
import_path = /Users/***/.modular/pkg/packages.modular.com_mojo/lib/mojo,/path/to/packages
[mojo]
import_path = /Users/***/.modular/pkg/packages.modular.com_mojo/lib/mojo,/path/to/packages
So, dir /path/to/packages/ is where I direct the "package" command's output. E.g., mojo package SomePkg -o /path/to/packages/SomePkg.mojopkg. As a result, I can do:
from SomePkg import SomeThing
from SomePkg import SomeThing
I can do that without copying the .mojopkg file into every project that uses it. Of note: there is both a [mojo] and a [mojo-nightly] section in the file ~/.modular/modular.cfg. If you want both stable and nightly to import from the same dir, then you need to add ,/path/to/packages to both sections' respective import_path setting. :mojo: :mojonightly:
Modular
YouTube
Modular Community Livestream - Mojo🔥 on Mac
Mojo🔥 on Mac (Apple Silicon) is going to be here soon! Join us on our upcoming community livestream as we discuss all things Mojo🔥 on Mac! We'll walk you through getting started with Mojo🔥 Mac, discuss Mac specific features, and show you how to build and run Mojo🔥 applications using Visual Studio on Mac! We have lots of cool demos and a communit...
1 Reply
bunny
bunny2w ago
@ViynShade @MyriadColors Also of note: when you update (i.e. modular update nightly/mojo) then you need to go fix your modular.cfg file again. 😐 Just wrinkles in an early language. Don't let it deter you from playing with Mojo. All languages are a bit rough around the edges when they first emerge onto the scene.