Issue running the vector_addition example

Hello, I followed instructions in GitHub - modular/modular: The Modular Platform (includes MAX & Mojo)

pip install modular

When I run the vector additition example under modular/examples/custom_ops/kernels, I get this error:

mojo run vector_addition.mojo
/home/lab/username/modular/examples/custom_ops/kernels/vector_addition.mojo:74:2: error: ‘VectorAddition’ has no ‘compiler’ member
@compiler.register(“vector_addition”)
^~~~~~~~
/home/lab/username/venv/bin/mojo: error: failed to parse the provided Mojo source module

Mojo version is

mojo --version
Mojo 25.5.0 (573c06a4)

I notice that many examples also fail to compile. For example,

~/username/modular/examples/mojo$ mojo run mandelbrot.mojo
/home/lab/username/modular/examples/mojo/mandelbrot.mojo:15:42: error: module ‘info’ does not contain ‘simd_width_of’
from sys.info import num_physical_cores, simd_width_of
^
/home/lab/username/modular/examples/mojo/mandelbrot.mojo:55:41: error: no matching function in initialization
var t = SIMDDType.bool, simd_width
~~~~~~~~~~~~~~~~~~^

nbody:

mojo run nbody.mojo
/home/lab/username/modular/examples/mojo/nbody.mojo:28:15: error: ‘Planet’ has no ‘ImplicitlyCopyable’ member
struct Planet(ImplicitlyCopyable, Movable):

Sorry you have installation issues. Please first check if the Packages | Modular are met. Then the main branch is tracking the nightly releases and pip install modular installs the latest stable Packages | Modular version which is currently 25.5. So

git clone https://github.com/modular/modular
cd modular
git checkout modular/v25.5
cd modular/examples/mojo

For pip, it’s highly recommended to use virtual environment so

# make sure no env is active
python -m venv venv
source venv/bin/activate
python -m pip install modular

The modular package is a meta-package that includes everything such as mojo-compiler , mojo (dev dependencies such as formater, LSP etc.) and max

Now check mojo –-version should match the tag Mojo 25.5.0 (573c06a4)

Then run

mojo mandelbrot.mojo 
Number of physical cores: 12
Vectorized: 11.305873239436618 ms
Parallelized: 2.309573 ms
Parallel speedup: 4.895222294093592

For the custom_ops examples, the kernels are meant to be used with max python graph api so we can run the vector addition example via (cd custom_ops)

python vector_addition.py

outputs like

Left-hand-side values:
[0.37531552 0.16229668 0.39715832 0.6472096  0.20262577 0.4971949
 0.24008769 0.9813841  0.37782624 0.37180763]

Right-hand-side values:
[0.925224   0.32441604 0.32967967 0.30302358 0.36905172 0.57079685
 0.35871768 0.14324683 0.10780976 0.15608703]

Graph result:
[1.3005395  0.48671272 0.726838   0.95023316 0.5716775  1.0679917
 0.59880537 1.1246309  0.485636   0.5278947 ]

Expected result:
[1.3005395  0.48671272 0.726838   0.95023316 0.5716775  1.0679917
 0.59880537 1.1246309  0.485636   0.5278947 ]

Generally for best environment and package/dependency management experience we recommend to use either pixi or uv.

With pixi there’s no need to manually handing venv, python version etc. For example in the case of custom_ops can do pixi run vector_addition where pixi handles everything correctly here.

If you’re interested about GPU programming in Mojo, please check out GitHub - modular/mojo-gpu-puzzles: Learn GPU Programming in Mojo🔥 by Solving Puzzles .