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

[Build] ModuleNotFoundError: No module named 'onnxruntime.capi' #21317

Open
lzivan opened this issue Jul 11, 2024 · 3 comments
Open

[Build] ModuleNotFoundError: No module named 'onnxruntime.capi' #21317

lzivan opened this issue Jul 11, 2024 · 3 comments
Labels
api issues related to all other APIs: C, C++, Python, etc. build build issues; typically submitted using template platform:windows issues related to the Windows platform

Comments

@lzivan
Copy link

lzivan commented Jul 11, 2024

Describe the issue

Hi team,

I'm using CPU build from source.

.\build.bat --config RelWithDebInfo --build_shared_lib --parallel --build_wheel --skip_tests

The build is successfully done. Now I'm using conda with python 3.11.
The WHL file is under build\Windows\RelWithDebInfo\RelWithDebInfo\dist.

pip install onnxruntime-1.19.0-cp311-cp311-win_amd64.whl

However, when I'm running onnxruntime-python-api.py

It presents:

Traceback (most recent call last):
  File "C:\Users\arda\zijie\onnxruntime\onnxruntime-python-api.py", line 7, in <module>
    import onnxruntime
  File "C:\Users\arda\zijie\onnxruntime\onnxruntime\__init__.py", line 54, in <module>
    from onnxruntime.capi import onnxruntime_validation
ModuleNotFoundError: No module named 'onnxruntime.capi'

So I checked the site-packages of onnxruntime under conda envs, it does exist.
image

Please help, I'm not sure whether some packages are lost during the installation from whl.

Urgency

No response

Target platform

Onnxruntime CPU

Build script

.\build.bat --config RelWithDebInfo --build_shared_lib --parallel --build_wheel --skip_tests

pip install onnxruntime-1.19.0-cp311-cp311-win_amd64.whl

Error / output

Traceback (most recent call last):
  File "C:\Users\arda\zijie\onnxruntime\onnxruntime-python-api.py", line 7, in <module>
    import onnxruntime
  File "C:\Users\arda\zijie\onnxruntime\onnxruntime\__init__.py", line 54, in <module>
    from onnxruntime.capi import onnxruntime_validation
ModuleNotFoundError: No module named 'onnxruntime.capi'

Visual Studio Version

No response

GCC / Compiler Version

No response

@lzivan lzivan added the build build issues; typically submitted using template label Jul 11, 2024
@github-actions github-actions bot added the platform:windows issues related to the Windows platform label Jul 11, 2024
@lzivan
Copy link
Author

lzivan commented Jul 11, 2024

This is my pip list after installation from WHL.

Package           Version
----------------- ---------
coloredlogs       15.0.1
filelock          3.15.4
flatbuffers       24.3.25
fsspec            2024.6.1
humanfriendly     10.0
intel-openmp      2021.4.0
Jinja2            3.1.4
MarkupSafe        2.1.5
mkl               2021.4.0
mpmath            1.3.0
networkx          3.3
numpy             2.0.0
onnxruntime       1.19.0
packaging         24.1
pip               24.0
protobuf          5.27.2
pyreadline3       3.4.1
setuptools        70.2.0
sympy             1.13.0
tbb               2021.13.0
torch             2.3.1
typing_extensions 4.12.2
wheel             0.43.0

@mgehre-amd
Copy link

I had the same problem when running python scripts from the onnxruntime git checkout, because it contains a folder named "onnxruntime" which gets confused with the onnxruntime package.

@lzivan
Copy link
Author

lzivan commented Jul 12, 2024

Thanks for the response. I changed the name of the onnxruntime folder under the git repo, and it won't give me "onnxruntime.capi" error. But now it says "Module onnx is not installed".

According to the error log, "onnx" is called under "torch". For "torch", I manually installed it by "pip install" after installing the WHL file. So for "onnx", do I need to manually install it by "pip install onnx"? Btw "onnx" is not installed after installing the WHL.

Traceback (most recent call last):
  File "C:\Users\arda\miniforge3\envs\test-onnx\Lib\site-packages\torch\onnx\_internal\onnx_proto_utils.py", line 219, in _add_onnxscript_fn
    import onnx
ModuleNotFoundError: No module named 'onnx'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\arda\zijie\onnxruntime\onnxruntime-python-api.py", line 127, in <module>
    main()
    ^^^^^^
  File "C:\Users\arda\zijie\onnxruntime\onnxruntime-python-api.py", line 109, in main
    create_model()
  File "C:\Users\arda\zijie\onnxruntime\onnxruntime-python-api.py", line 30, in create_model
    torch.onnx.export(model(), (sample_x, sample_y), MODEL_FILE, input_names=["x", "y"], output_names=["z"],
  File "C:\Users\arda\miniforge3\envs\test-onnx\Lib\site-packages\torch\onnx\utils.py", line 516, in export
    _export(
  File "C:\Users\arda\miniforge3\envs\test-onnx\Lib\site-packages\torch\onnx\utils.py", line 1686, in _export
    proto = onnx_proto_utils._add_onnxscript_fn(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\arda\miniforge3\envs\test-onnx\Lib\site-packages\torch\onnx\_internal\onnx_proto_utils.py", line 221, in _add_onnxscript_fn
    raise errors.OnnxExporterError("Module onnx is not installed!") from e
torch.onnx.errors.OnnxExporterError: Module onnx is not installed!

@sophies927 sophies927 added the api issues related to all other APIs: C, C++, Python, etc. label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api issues related to all other APIs: C, C++, Python, etc. build build issues; typically submitted using template platform:windows issues related to the Windows platform
Projects
None yet
Development

No branches or pull requests

3 participants