Open JiaPai12138 opened 2 years 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.
Mark. I've encountered similar problem recently
Same issue when using pyinstaller. Anyway to suppress the warning?
i dont see any
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
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
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.
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)
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"
Describe the issue
Will see the following warning:
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:
Then cd to this path, open python, simple import the package
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