onnxruntime/onnxruntime/python/_pybind_state.py.in
Severin Simmler 90754fc077
Fix invalid escape sequence (#17145)
### Description
- Removed one unused import
- Escaped a backslash in a path

### Motivation and Context
I see this `DeprecationWarning` when I import `onnxruntime`:

```
onnxruntime/capi/_pybind_state.py:28: DeprecationWarning: invalid escape sequence '\S'
    "(other than %SystemRoot%\System32), "
```

A future version of Python (maybe 3.13?) will raise a `SyntaxError` for
invalid escape sequences.
2023-08-15 10:29:54 -07:00

33 lines
1.6 KiB
Python

# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
Ensure that dependencies are available and then load the extension module.
"""
import os
import platform
import warnings
from . import _ld_preload # noqa: F401
if platform.system() == "Windows":
from . import version_info
# If on Windows, check if this import error is caused by the user not installing the 2019 VC Runtime
# The VC Redist installer usually puts the VC Runtime dlls in the System32 folder, but it may also be found
# in some other locations.
# TODO, we may want to try to load the VC Runtime dlls instead of checking if the hardcoded file path
# is valid, and raise ImportError if the load fails
if version_info.vs2019 and platform.architecture()[0] == "64bit":
system_root = os.getenv("SystemRoot") or "C:\\Windows"
if not os.path.isfile(os.path.join(system_root, "System32", "vcruntime140_1.dll")):
warnings.warn("Please install the 2019 Visual C++ runtime and then try again. "
"If you've installed the runtime in a non-standard location "
"(other than %SystemRoot%\\System32), "
"make sure it can be found by setting the correct path.")
@ONNXRUNTIME_IMPORT_PYTORCH_TO_RESOLVE_DLLS@
@ONNXRUNTIME_SETDLOPENFLAGS_GLOBAL@
from .onnxruntime_pybind11_state import * # noqa
@ONNXRUNTIME_SETDLOPENFLAGS_LOCAL@