Skip to content

Instantly share code, notes, and snippets.

@trevorhobenshield
Last active October 11, 2023 20:27
Show Gist options
  • Save trevorhobenshield/6bca58f947ad6115a113a97072df1a73 to your computer and use it in GitHub Desktop.
Save trevorhobenshield/6bca58f947ad6115a113a97072df1a73 to your computer and use it in GitHub Desktop.
Mojo Setup

1. Install LLVM

sudo apt install llvm
echo 'export LLVM_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer' >> ~/.bashrc

2. Find libpython path for your env

Assuming env located at ~/miniconda3

python3 -c 'import pathlib; sorted({print(x) for x in (pathlib.Path.home() / "miniconda3/envs").rglob("lib/*") if "libpython" in x.name})'

3. Export env

Replace <full_path_to_libpython.so> with your env's libpython path

echo 'export MOJO_PYTHON_LIBRARY="<full_path_to_libpython.so>"' >> ~/.bashrc
source ~/.bashrc

4. Install Modular CLI / Mojo

Replace <your key> with key provided at developer.modular.com/download

curl https://get.modular.com | MODULAR_AUTH=<your key> sh -
modular install mojo
echo 'export MODULAR_HOME="$HOME/.modular"' >> ~/.bashrc
echo 'export PATH="$MODULAR_HOME/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

5. Activate env and run

from python import Python as py

fn main() raises:
    let np = py.import_module("numpy")
    print(np.random.randn(3,7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment