Complete guide to installing CML Python bindings.
# Check Python version (3.8+)
python3 --version
# Check if pip is available
python3 -m pip --version# 1. Ensure C-ML library is built
cd .. # Go to C-ML root
make # Build C library
# 2. Install Python bindings
cd python
pip3 install cffi
python3 setup.py install
# 3. Verify
python3 -c "import cml; cml.init(); print('Success!'); cml.cleanup()"The Python bindings require the compiled C library.
Using Make:
cd ..
makeThis creates:
build/lib/libcml.a(static)build/lib/libcml.so(shared, if built)
Using CMake:
cd ..
mkdir -p build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make -j$(nproc)
cd ..# Install CFFI (required for building bindings)
pip3 install cffi
# Optional: install development tools
pip3 install setuptools wheel buildOption A: Automatic (recommended)
cd python
python3 setup.py build_ext --inplaceOption B: Manual
cd python
python3 cml/build_cffi.pySystem-wide installation:
python3 setup.py installUser installation (no sudo):
python3 setup.py install --userDevelopment mode (editable):
pip3 install -e .Development mode is recommended for development work.
Test basic functionality:
python3 << 'EOF'
import cml
cml.init()
print("CML initialized")
x = cml.randn([10, 10])
print(f"Created tensor with {x.size} elements")
y = cml.zeros([10, 10])
z = x + y
print("Tensor operations work")
cml.cleanup()
print("CML Python bindings working!")
EOF# Install dependencies
sudo apt-get update
sudo apt-get install python3-dev python3-pip
# Install CFFI
pip3 install cffi
# Build and install
cd python
python3 setup.py install# Install dependencies
sudo pacman -S python python-pip
# Install CFFI
pip install cffi
# Build and install
cd python
python setup.py install# Install dependencies (if using Homebrew)
brew install python3
# Install CFFI
pip3 install cffi
# Build and install
cd python
python3 setup.py installIf using LLVM from Homebrew:
export LDFLAGS="-L$(brew --prefix llvm@18)/lib"
export CPPFLAGS="-I$(brew --prefix llvm@18)/include"
python3 setup.py build_ext --inplaceUse WSL2 with Ubuntu and follow Linux instructions.
Native Windows (advanced):
# Install Python from python.org or Microsoft Store
# Install dependencies
pip install cffi
# Build C library with CMake
cd ..
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A x64 ..
cmake --build . --config Release
# Build Python bindings
cd ..\python
python setup.py build_ext --inplace
python setup.py installModuleNotFoundError: No module named 'cffi'
Solution:
pip3 install cffiOSError: cannot open shared object file
Solution:
# Rebuild C library
cd ..
make clean
make
# Then rebuild bindings
cd python
python3 setup.py build_ext --inplaceERROR: MLIR not found
Solution:
# Set MLIR path explicitly
export MLIR_DIR=/path/to/mlir/lib/cmake/mlir
cd python
python3 setup.py build_ext --inplaceImportError: libcml.so.18: cannot open shared object file
Solution:
# Set library path
export LD_LIBRARY_PATH=$(pwd)/../build/lib:$LD_LIBRARY_PATH
# Or create symbolic link
ln -s ../build/lib/libcml.so ./
# Then test
python3 -c "import cml"PermissionError: [Errno 13] Permission denied
Solution:
Install as user instead:
python3 setup.py install --user
# Or use pip with user flag
pip3 install --user -e .ERROR: Python version X.X does not match requirement >=3.8
Solution:
Ensure Python 3.8+ is installed and used:
# Check version
python3 --version
# Use explicit Python path
/usr/bin/python3.10 setup.py install
# Or create virtual environment
python3 -m venv venv
source venv/bin/activate
pip install cffi
python setup.py installRecommended for development:
# Create virtual environment
python3 -m venv cml_env
# Activate it
source cml_env/bin/activate # On Windows: cml_env\Scripts\activate
# Install dependencies
pip install cffi
# Build and install
cd python
python setup.py develop
# Test
python -c "import cml; print('OK')"
# Deactivate when done
deactivatecd python
# Build wheel
pip install wheel
python -m build
# Output in dist/
ls dist/pip install dist/cml-*.whlpip uninstall cmlcd python
python setup.py install --record files.txt
xargs rm -f < files.txtpython3 << 'EOF'
import sys
print(f"Python: {sys.version}")
try:
import cml
print(f"CML: OK")
# Test basic operations
cml.init()
x = cml.randn([10, 10])
cml.cleanup()
print("All tests passed!")
sys.exit(0)
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
EOFcd examples
python3 01_hello_cml.py
python3 02_neural_network.py- See API Reference for API documentation
- See Examples for usage examples
- See Documentation for all CML docs
- Build issues: Check build logs, ensure dependencies are installed
- Runtime issues: Set
export LD_LIBRARY_PATH=../../build/lib:$LD_LIBRARY_PATH - API questions: See API_GUIDE.md
- Examples: Check examples/ folder
- CML Python Bindings: v0.0.3
- Minimum Python: 3.8
- CFFI Requirement: 1.14.0+
- C Standard: C11
- MLIR Requirement: 18.x+