This guide covers how to install NKIPy and its dependencies on an AWS Trainium instance.
NKIPy requires a Trainium instance with the Neuron Driver and Runtime installed.
If you are using a Neuron Multi-Framework DLAMI, the driver and runtime are already installed. You can skip to the next section.
Otherwise, follow the Neuron Setup Guide up to the "Install Drivers and Tools" section for your OS. Note that NKIPy does not require PyTorch, but it supports Torch tensors if available.
uv is a fast Python package manager. It's the recommended way to install NKIPy.
curl -LsSf https://astral.sh/uv/install.sh | shgit clone https://github.com/aws-neuron/nkipy.git
cd nkipy
# Install all packages (creates .venv automatically)
uv syncThis single command will:
- Create a
.venvvirtual environment - Install
nkipyandspikein editable mode - Install all dependencies including
neuronx-ccfrom the Neuron repository - Install development tools (pytest, ruff, mypy)
You can run commands in two ways:
Option 1: Activate the virtual environment
# Activate the environment
source .venv/bin/activate
# Now run commands directly
python examples/playground/simple_nkipy_kernel.py
python -c "import nkipy; import spike"
# Deactivate when done
deactivateOption 2: Use uv run without activation
# Run Python with the workspace environment
uv run python examples/playground/simple_nkipy_kernel.py
# Start an interactive Python session
uv run python# Build nkipy
uv build --package nkipy
# Build spike
uv build --package spike
# Output will be in dist/
ls dist/If you prefer using pip instead of uv, follow these instructions.
python3.10 -m venv nkipy_venv
source nkipy_venv/bin/activateNKIPy depends on the Neuron Compiler (neuronx-cc). Configure pip to use the Neuron repository:
pip config set global.extra-index-url https://pip.repos.neuron.amazonaws.comNKIPy and Spike are not published on PyPI and must be installed from source using the local directory paths:
# Install both packages in editable mode
pip install -e ./nkipy -e ./spike
# Or install without editable mode
pip install ./nkipy ./spike# Install build tool
pip install build
# Build wheel packages
python -m build nkipy --wheel --outdir dist
python -m build spike --wheel --outdir dist
# Install the built wheels
pip install dist/*.whlAfter installation, verify that everything works:
# With uv
uv run python -c "import nkipy; import spike; print('Installation successful!')"
# With pip (after activating venv)
python -c "import nkipy; import spike; print('Installation successful!')"If you see an error about neuronx-cc not being found:
With uv: The Neuron repository is already configured in pyproject.toml. Try running uv sync --refresh.
With pip: Make sure you've configured the extra index URL:
pip config set global.extra-index-url https://pip.repos.neuron.amazonaws.comThe spike package contains C++ code that requires compilation. Ensure you have:
- CMake installed (
apt install cmake) - A C++ compiler (gcc/clang)
- Python development headers (
apt install python3-dev) - Neuron Runtime (libnrt) installed