iree icon indicating copy to clipboard operation
iree copied to clipboard

ImportError: cannot import name '_runtime' from 'iree._runtime_libs' (unknown location)

Open muwys518 opened this issue 1 year ago • 2 comments

What happened?

Traceback (most recent call last): File "", line 1, in File "/home/roger.luo/workspace/test/iree/code/iree-build-base/runtime/bindings/python/iree/runtime/init.py", line 13, in from . import _binding File "/home/roger.luo/workspace/test/iree/code/iree-build-base/runtime/bindings/python/iree/runtime/_binding.py", line 19, in from .._runtime.libs import _runtime ImportError: cannot import name '_runtime' from 'iree._runtime_libs' (unknown location)

Steps to reproduce your issue

  1. cmake -GNinja -B ../iree-build-base -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_C_COMPILER=/usr/bin/clang-9 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-9 -DCMAKE_INSTALL_PREFIX=../iree-build-base/install -DCMAKE_BUILD_TYPE=RelWithDebInfo -DIREE_BUILD_PYTHON_BINDINGS=ON -DPython3_EXECUTABLE="$(which python)" .
  2. cmake --build ../iree-build-base --target install
  3. source ../iree-build-base/.env && export PYTHONPATH
  4. python -c "import iree.compiler"
  5. python -c "import iree.runtime"
  6. See error

What component(s) does this issue relate to?

Python

Version information

commit eda28bf01d10d13f86df9018cb1f35a2dcb1cadc (HEAD -> main, origin/main, origin/HEAD) Author: Lei Zhang [email protected] Date: Sun Mar 3 17:37:23 2024 -0800

[hip][rocm] Fix hipGetDeviceProperties usage after ROCm 6.0 (#16643)

ROCm 6.0 changes the `hipDeviceProp_t` struct, so we would need the new
`hipGetDevicePropertiesR0600()` API to query it--the existing
`hipGetDeviceProperties()`l API won't work for our case with dynamic
libraries.

Related to https://github.com/ROCm/ROCm/issues/2728

Additional context

No response

muwys518 avatar Mar 04 '24 06:03 muwys518

I'm not sure that the flag -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON

is going to work for a dev build like this as I think it sets up an rpath that does not match the organization of the build tree.

This can be verified by running ldd on the _runtime.*.so in the python path. If it shows that libraries were not found, that would be the problem. Note that when Python has an error loading a native library, it reports it as not found.

stellaraccident avatar Mar 04 '24 06:03 stellaraccident

I'm not sure that the flag -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON

is going to work for a dev build like this as I think it sets up an rpath that does not match the organization of the build tree.

This can be verified by running ldd on the _runtime.*.so in the python path. If it shows that libraries were not found, that would be the problem. Note that when Python has an error loading a native library, it reports it as not found.

I used the following command, but the problem still persists: cmake -GNinja -B ../iree-build-base -DCMAKE_C_COMPILER=/usr/bin/clang-9 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-9 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DIREE_BUILD_PYTHON_BINDINGS=ON -DPython3_EXECUTABLE="$(which python)" .

I have any other step error?

muwys518 avatar Mar 04 '24 06:03 muwys518

Is this error solved?

bailuan avatar Mar 18 '24 02:03 bailuan

This error occurs under conda virtual env, but it is fine under conda base env.

bailuan avatar Mar 18 '24 02:03 bailuan

This error occurs under conda virtual env, but it is fine under conda base env.

I'm not sure,I have build python package to solve it.

muwys518 avatar Mar 18 '24 03:03 muwys518

You mean that you use pip install ? That still didn't solve the issue.

bailuan avatar Mar 18 '24 07:03 bailuan

I don't have enough information to even speculate at the problem. The problem sounds environmental. I would need a docker image or equivalent information to reproduce.

Nine times out of ten this is due to an improper python setup, mismatched python versions or a basic inability for the os to load the shared library.

stellaraccident avatar Mar 18 '24 07:03 stellaraccident

You mean that you use pip install ? That still didn't solve the issue.

I use ./build_tools/python_deploy/build_linux_packages.sh to build new version package then I use pip install the new version package in conda env, I can use package continue, but still didn't solve the issue, You are right. I have no idea for this problem

muwys518 avatar Mar 19 '24 08:03 muwys518

I don't have enough information to even speculate at the problem. The problem sounds environmental. I would need a docker image or equivalent information to reproduce.

Nine times out of ten this is due to an improper python setup, mismatched python versions or a basic inability for the os to load the shared library.

It seems like it's an environmental issue.

muwys518 avatar Mar 19 '24 08:03 muwys518

This error occurs under conda virtual env, but it is fine under conda base env.

I have same problem in conda base env

muwys518 avatar Mar 19 '24 08:03 muwys518

Though I didn't figure out why this happened, I strongly suggest stop using anaconda. I use pyvenv instead of conda, no error happened any more even under virtual envs.

bailuan avatar Mar 19 '24 09:03 bailuan

This error occurs under conda virtual env, but it is fine under conda base env.

I have same problem in conda base env

do not use conda, it is not a good choice, in my opinion.

bailuan avatar Mar 19 '24 09:03 bailuan

Though I didn't figure out why this happened, I strongly suggest stop using anaconda. I use pyvenv instead of conda, no error happened any more even under virtual envs.

thanks, I‘ll try it

muwys518 avatar Mar 19 '24 09:03 muwys518

I don't have enough information to even speculate at the problem. The problem sounds environmental. I would need a docker image or equivalent information to reproduce.

Nine times out of ten this is due to an improper python setup, mismatched python versions or a basic inability for the os to load the shared library.

I think I have found the reason. The python environment for building the python package needs to be the same as the python environment for python -c. If there is a difference, there will be problems.

muwys518 avatar Mar 19 '24 09:03 muwys518

Though I didn't figure out why this happened, I strongly suggest stop using anaconda. I use pyvenv instead of conda, no error happened any more even under virtual envs.

I think I have found the reason. The python environment for building the python package needs to be the same as the python environment for python -c. If there is a difference, there will be problems.

muwys518 avatar Mar 19 '24 09:03 muwys518

Maybe, but I have encountered several problem under conda, not only this one _

bailuan avatar Mar 19 '24 09:03 bailuan

Maybe, but I have encountered several problem under conda, not only this one _

I have solved this problem, previously I was building in the container and referencing the python package outside the container. Now after I set the python interpreter inside the container and outside the container to be consistent, the problem has not occurred.

muwys518 avatar Mar 19 '24 10:03 muwys518

I don't have enough information to even speculate at the problem. The problem sounds environmental. I would need a docker image or equivalent information to reproduce.

Nine times out of ten this is due to an improper python setup, mismatched python versions or a basic inability for the os to load the shared library.

I have solved this problem, previously I was building in the container and referencing the python package outside the container. Now after I set the python interpreter inside the container and outside the container to be consistent, the problem has not occurred. Thank you!

muwys518 avatar Mar 19 '24 10:03 muwys518