[MLIR] Python Bindings Setup

Hi! I am new to MLIR, I am trying to set up Python bindings as per this guide but I am running into some issues.

In a virtual env, I ran the following in a build folder to configure and build LLVM and MLIR.

► cmake -G Ninja ../llvm \                                                                                                                                         (tvm-test-env) 
          -DLLVM_ENABLE_PROJECTS=mlir \
          -DLLVM_BUILD_EXAMPLES=ON \
          -DLLVM_TARGETS_TO_BUILD=all \
          -DCMAKE_BUILD_TYPE=Release \
          -DLLVM_ENABLE_ASSERTIONS=ON \
          -DMLIR_INCLUDE_INTEGRATION_TESTS=ON \
          -DMLIR_ENABLE_BINDINGS_PYTHON=ON

► cmake --build . --target check-mlir 

Then I exported the path to mlir_core to the PYTHONPATH, as specified by the guide, and ran ninja install.

python3 -c "import mlir" works fine if I run it in the LLVM directory but mlir is not found when running it in any other directory and I can’t import it to a Python file.

If anyone could let me know what I am doing wrong, it would be greatly appreciated. Thanks!

Most likely you’re having this same problem MLIR Python bindings: .pyi imports? - #8 by makslevental.

Hi, thank you for your quick reply! The cpython version and the Python version (3.12) I am running match. I checked the versions in the requirements file and they also seem to be the right version. I am really not sure what is wrong?

Can you post the entire error

I rebuilt the project in an new venv and it seems to be working now. Thank you for your help.

1 Like