Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import onnxruntime Error:cannot import name 'get_all_providers' #3943

Closed
manofmountain opened this issue May 14, 2020 · 8 comments
Closed

import onnxruntime Error:cannot import name 'get_all_providers' #3943

manofmountain opened this issue May 14, 2020 · 8 comments

Comments

@manofmountain
Copy link

Describe the bug
Manually build onnxruntime with python wheel and encounter such an issue while launching related python test at the end of the building process.

Urgency
M

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04
  • ONNX Runtime installed from (source or binary): source
  • ONNX Runtime version: 1.3.0
  • Python version: 3.6.6
  • Visual Studio version (if applicable):
  • GCC/Compiler version (if compiling from source): 5.4
  • CUDA/cuDNN version:
  • GPU model and memory:

To Reproduce

  • Describe steps/code to reproduce the behavior.
    my source build command is: ./build.sh --config Debug --build_shared_lib --parallel --build_wheel
  • Attach the ONNX model to the issue (where applicable) to expedite investigation.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
when I import onnxruntime ,Error is follow: (BTW, i definitely activate python 3.6.6 before the source building.

2020-05-15 00:32:40,450 Build [DEBUG] - Running subprocess in '/home/lshusen/onnxruntime/build/Linux/Debug'
['/home/lshusen/workspace/py36/bin/python3', 'onnxruntime_test_python.py']
/mnt/ssd/lshusen/onnxruntime/build/Linux/Debug/onnxruntime/capi/_pybind_state.py:13: UserWarning: Cannot load onnxruntime.capi. Error: 'Python version
mismatch: module was compiled for Python 3.5, but the interpreter version is incompatible: 3.6.6 (default, Apr 18 2020, 18:55:01)
[GCC 5.4.0 20160609].'
warnings.warn("Cannot load onnxruntime.capi. Error: '{0}'".format(str(e)))
Traceback (most recent call last):
File "onnxruntime_test_python.py", line 8, in
import onnxruntime as onnxrt
File "/mnt/ssd/lshusen/onnxruntime/build/Linux/Debug/onnxruntime/init.py", line 12, in
from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device, set_seed, RunOptions, SessionOptions, set_defaul
t_logger_severity, NodeArg, ModelMetadata, GraphOptimizationLevel, ExecutionMode, OrtDevice, SessionIOBinding
ImportError: cannot import name 'get_all_providers'
Traceback (most recent call last):
File "/home/lshusen/onnxruntime/tools/ci_build/build.py", line 1740, in
sys.exit(main())
File "/home/lshusen/onnxruntime/tools/ci_build/build.py", line 1640, in main
args.use_tvm, args.use_tensorrt)
File "/home/lshusen/onnxruntime/tools/ci_build/build.py", line 1102, in run_onnxruntime_tests
cwd=cwd, dll_path=dll_path)
File "/home/lshusen/onnxruntime/tools/ci_build/build.py", line 391, in run_subprocess
env=my_env, shell=shell)
File "/home/lshusen/bin/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/home/lshusen/workspace/py36/bin/python3', 'onnxruntime_test_python.py']' returned non-zero exit status 1.
(py36) ➜ /home/lshusen/onnxruntime (rel-1.3.0) vim build.log

@pranavsharma
Copy link
Contributor

Can you do this in a clean environment (possibly using conda)? The error seems to be pretty clear - Error: 'Python version
mismatch: module was compiled for Python 3.5, but the interpreter version is incompatible: 3.6.6.

@manofmountain
Copy link
Author

@pranavsharma Thank you for your quick reply, really appreciate that.. i'm using a virtualenv environment with python 3.6.6..Do we have some debug methods to check where python 3.5 involved during the building process?

@manofmountain
Copy link
Author

It's not easy to make my whole project built with conda as it has been done on a py36 virtual env for quite a long time. Through the build log, seems cmake can find my py36 interpreter correctly.

image

@pranavsharma
Copy link
Contributor

pranavsharma commented May 16, 2020

I was able to repro this in my py36 venv. I've 3.5.2 outside the venv and 3.6.10 inside.
Running the following should resolve your issue. I tried it on my machine.

./build.sh --build_shared --build_wheel --parallel --cmake_extra_defines PYTHON_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1 PYTHON_EXECUTABLE=/home/pranav/venv/bin/python3 PYTHON_INCLUDE_DIRS=/usr/include/python3.6m/

@jywu-msft
Copy link
Member

I was able to repro this in my py36 venv. I've 3.5.2 outside the venv and 3.6.10 inside.
Running the following should resolve your issue. I tried it on my machine.

./build.sh --build_shared --build_wheel --parallel --cmake_extra_defines PYTHON_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1 PYTHON_EXECUTABLE=/home/pranav/venv/bin/python3 PYTHON_INCLUDE_DIRS=/usr/include/python3.6m/

is this a PATH issue? Is it finding python 3.5 before 3.6?
It's strange, if cmake detects the correct PYTHON version, we should be using the libraries/headers associated with that one. so there must be something wrong with the cmake scripts.

@pranavsharma
Copy link
Contributor

I was able to repro this in my py36 venv. I've 3.5.2 outside the venv and 3.6.10 inside.
Running the following should resolve your issue. I tried it on my machine.

./build.sh --build_shared --build_wheel --parallel --cmake_extra_defines PYTHON_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1 PYTHON_EXECUTABLE=/home/pranav/venv/bin/python3 PYTHON_INCLUDE_DIRS=/usr/include/python3.6m/

is this a PATH issue? Is it finding python 3.5 before 3.6?
It's strange, if cmake detects the correct PYTHON version, we should be using the libraries/headers associated with that one. so there must be something wrong with the cmake scripts.

Yes, it was using 3.5 libs even though both 3.5 and 3.6 libs are present in the same dir (/usr/lib/x86_64-linux-gnu/). I retried in a new terminal window and can't seem to repro it anymore.

@pranavsharma
Copy link
Contributor

@manofmountain any more questions? Does this resolve your issue?

@pranavsharma
Copy link
Contributor

plz reopen if this doesn't resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants