
The Mojo toolchain can be used with Modular’s package deal supervisor and challenge administration instrument, pixi. You should utilize pixi to handle Mojo-only initiatives in addition to initiatives that mix Mojo and Python, because it helps all of the metadata utilized in Python initiatives (e.g., pyproject.toml). The instrument additionally supplies lockfile and environment-management mechanisms. Among the demo initiatives within the Mojo repository use pixi, nevertheless it’s fully attainable to maintain utilizing pip or uv if you happen to’ve already invested in these instruments.
Working with Python in Mojo
Whenever you write Mojo code, the default assumption is that every part you kind is Mojo. If you wish to use Python options, it’s a must to import them particularly. For example, if you happen to needed to make use of NumPy from Python to do one thing particular to it (like integrating it with an present workflow), you’d do one thing like this:
from python import Python
def fundamental():
np = Python.import_module("numpy")
rand_array = np.random.rand(32)
The Mojo module python supplies interop with the Python ecosystem as an entire, and the Python.import_module technique works like Python’s personal import mechanism. Each normal library merchandise in Python, together with each third-party module put in into the digital atmosphere you’re utilizing, might be imported this fashion. Imports do have some restrictions—you may’t import into the highest stage of a Mojo module, and you’ll’t emulate from x import y behaviors but.

