microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.22k stars 2.87k forks source link

Init provider bridge failed when put onnxruntime folder under path which contains other Unicode character #13499

Open JiaPai12138 opened 1 year ago

JiaPai12138 commented 1 year ago

Describe the issue

Will see the following warning:

2022-10-28 19:54:16.5781916 [W:onnxruntime:Default, onnxruntime_pybind_state.cc:1622 onnxruntime::python::CreateInferencePybindStateModule] Init provider bridge failed.

Just a bit annoying, no big issue

To reproduce

Copy whole "onnxruntime" folder to another path which contains characters other than normal letters/signals For example:

F:\Tiếng Việt\
F:\中文\
F:\فارسی‎ = Fârsi\
...

Then cd to this path, open python, simple import the package

import onnxruntime

You will get warning, but you can still use the package as normal so no big issue

Urgency

No

Platform

Windows

OS Version

Win 10 21H2

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.13.1 (actually since version 1.10.0)

ONNX Runtime API

Python

Architecture

X64

Execution Provider

DirectML

Execution Provider Library Version

No response

m3et commented 1 year ago

Hey,

Any ideas on how to suppress this warning message? Using set_default_logger_severity can only be done after importing the package so it's too late.

I tried to wrap around stdout and stderr to disable it right before importing, but no luck.

@contextmanager
def suppress_stdout():
    with open(os.devnull, "w") as devnull:
        old_stdout = sys.stdout
        old_stderr = sys.stderr
        sys.stdout = devnull
        sys.stderr = devnull

        try:
            yield
        finally:
            sys.stdout = old_stdout
            sys.stderr = old_stderr

with suppress_stdout():
    import onnxruntime

Any idea will be much appreciated.

SStarver commented 1 year ago

Mark. I've encountered similar problem recently

akanksha-atrey commented 1 year ago

Same issue when using pyinstaller. Anyway to suppress the warning?

JiaPai12138 commented 1 year ago

i dont see any

aa0308qq commented 9 months ago

In PyInstaller Consider using --add-data libonnxruntime_providers_shared.so:. into PyInstaller. The file libonnxruntime_providers_shared.so can be found in python_path/site-packages/onnxruntime/capi

Kyyds commented 8 months ago

In PyInstaller Consider using --add-data libonnxruntime_providers_shared.so:. into PyInstaller. The file libonnxruntime_providers_shared.so can be found in python_path/site-packages/onnxruntime/capi

@aa0308qq Many thanks! Works for me.

A few words about my case: On Windows10, Use -D when package my program through Pyinstaller, and the EXE works fine but with this warning.

Find and copy onnxruntime_providers_shared.dll in MY_PROJECT_ROOT/venv/Lib/site-packages/onnxruntime/capi, and paste it into dist/YOUR_EXE_NAME/_internal/onnxruntime/capi

fromm1990 commented 5 months ago

Hi, I have combined @aa0308qq and @Kyyds answers into the following hook:

from pathlib import Path

from PyInstaller import compat
from PyInstaller.utils.hooks import get_package_paths

shared_lib = None

if compat.is_win:
    shared_lib = "onnxruntime_providers_shared.dll"
elif compat.is_linux:
    shared_lib = "libonnxruntime_providers_shared.so"
else:
    raise NotImplementedError("Unsupported platform")

_, pkg_dir = get_package_paths("onnxruntime")
pkg_dir = Path(pkg_dir)
lib_file = pkg_dir.joinpath("capi", shared_lib)
binaries = [(lib_file.as_posix(), ".")]

Save the code above into a file called hook-onnxruntime.py. Finally, tell pyinstaller where to find your new hook by supplying the following option --additional-hooks-dir=path/to/your/hook_dir.

These steps should result in a fully automatic build process, without the need to copy the libonnxruntime_providers_shared.so or the onnxruntime_providers_shared.dll file manually.

zarzouram commented 4 months ago

Hi, I solved it by adding the below snippet to the spec file. It will include the libonnxruntime_providers_shared.so or the respective dll file in your PyInstaller executable.

from PyInstaller.utils.hooks import collect_dynamic_libs
# Collect dynamic libraries from onnxruntime
binaries= collect_dynamic_libs('onnxruntime', destdir='onnxruntime/capi')

# Add datas to binaries
a = Analysis(['your_main_file.py'],
             pathex =['path_to_your_project'],
             binaries=binaries,
             datas=[],  # Add collected dynamic libs
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
samfisherirl commented 2 weeks ago

windows pyinstaller bat

@echo off
SET venv_dir=venv
SET python=%venv_dir%\Scripts\python.exe
SET torch=%venv_dir%\Lib\site-packages\torch\lib
SET onnix=%venv_dir%/Lib/site-packages/onnxruntime/capi
SET pyinstaller=%venv_dir%\Scripts\pyinstaller.exe

CALL .\venv\Scripts\activate

%python% -m pip install --upgrade setuptools pyinstaller

%pyinstaller% --console   --noconfirm --clean --add-data="%torch%;torch\lib" --add-data="%onnix%;onnxruntime\capi" C:\Users\dower\Documents\unsilence_2\unsilence\Unsilence.py"