iree
iree copied to clipboard
Incorrect import statement generated in python bindings
What happened?
During the binding generation process the following line is created in iree-build/runtime/bindings/python/iree/runtime/_binding.py
:
from .._runtime.libs import _runtime
This causes an error when trying to import iree-runtime python modules.
This can be trivially fixed by replacing the line above with
from .._runtime_libs import _runtime
Unfortunately, I'm not familiar with the binding generation methods used and cannot come up with an MR to fix it.
Steps to reproduce your issue
- Build IREE with python bindings
- Try to import iree-runtime into a python script
What component(s) does this issue relate to?
Python
Version information
14895845b Adding iree-benchmark-executable help text for CUDA.
Additional context
No response
Hm, this seems odd to me because I run like this every day. If possible, I'd like to figure out how to repro what you are seeing so we have a better chance of it but recurring.
I know it sounds weird, but can you confirm what directory you are running from, where the script is and what import line is used in the script?
Anonomyzed is fine: there are just portion path extension things that go badly based on some of these variables.
This is the way to reproduce it (for me at least):
Configure, build, install:
cmake -G Ninja -B ../iree-build -S . \
...
-DIREE_BUILD_PYTHON_BINDINGS=ON \
-DPython3_EXECUTABLE="$(which python3)" \
-DCMAKE_INSTALL_PREFIX="${HOME}/.local" \
...
.
cmake --build ../iree-build
cmake --install ../iree-build
Point to the module:
export PYTHONPATH=${PYTHONPATH}:${HOME}/.local/python_packages/iree_runtime
Run:
python3
Python 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import iree.runtime
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dmitry/.local/python_packages/iree_runtime/iree/runtime/__init__.py", line 13, in <module>
from . import _binding
File "/home/dmitry/.local/python_packages/iree_runtime/iree/runtime/_binding.py", line 19, in <module>
from .._runtime.libs import _runtime
ModuleNotFoundError: No module named 'iree._runtime'
>>>
Go to ~/.local/python_packages/iree_runtime/iree/runtime/_binding.py
and replace from .._runtime.libs
with from .._runtime_libs
Test:
python3
Python 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import iree.runtime
>>>
I am seeing this as well.
cmake -G Ninja -S ../ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DIREE_ENABLE_ASSERTIONS=ON \
-DIREE_ENABLE_SPLIT_DWARF=ON \
-DIREE_ENABLE_THIN_ARCHIVES=ON \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DIREE_ENABLE_LLD=ON \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DIREE_HAL_DRIVER_CUDA=OFF \
-DIREE_TARGET_BACKEND_CUDA=OFF \
-DCMAKE_INSTALL_PREFIX=/path/to/install/ \
-DIREE_TARGET_BACKEND_ROCM=ON \
-DIREE_HAL_DRIVER_HIP=ON \
-DIREE_TARGET_BACKEND_LLVM_CPU=ON \
-DIREE_ROCM_PATH=/opt/rocm/ \
-DIREE_BUILD_PYTHON_BINDINGS=ON \
-DPython3_EXECUTABLE="$(which python)"
Followed by:
export PYTHONPATH=/path/to/install/python_packages/iree_runtime:/path/to/install/python_packages/iree_compiler:$PYTHONPATH