_pybind_state.py 1.5 KB

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