This guide will help you install and use the Python bindings for the Rust matrix library.
-
Python 3.8 or higher
python --version
-
Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env
-
pip (usually comes with Python)
# Clone the repository
git clone <your-repo-url>
cd self-LLM
# Run the automated build script
./build_python.sh# Install maturin (build tool)
pip install maturin
# Install development dependencies
pip install -r requirements.txt
# Build and install in development mode
maturin develop --release
# Test the installation
python -c "import matrix_lib_python as ml; print('Installation successful!')"Run the example to verify everything works:
python examples/python_example.pyRun the tests:
python -m pytest tests/test_python_bindings.py -vOnce installed, you can use the library in Python:
import matrix_lib_python as ml
# Create a matrix
matrix = ml.PyMatrix.from_list([
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]
])
# Create an array
array = ml.PyNDArray.zeros([2, 3, 4])
print(f"Matrix shape: {matrix.dimensions()}")
print(f"Array shape: {array.shape()}")- Import Error: Make sure you ran
maturin developsuccessfully - Build Errors: Ensure you have Rust installed and up to date
- Permission Errors: Try running with
sudoif needed (not recommended for development)
- Check the PYTHON_README.md for detailed documentation
- Run
cargo testto test the Rust code - Run
python -m pytest tests/to test the Python bindings
For development, install in editable mode:
maturin developThis will rebuild the library automatically when you make changes to the Rust code.