From 78ddcded185e60f83743faa194178a8e5979757b Mon Sep 17 00:00:00 2001 From: Austin Anderson Date: Fri, 13 Dec 2019 14:51:04 -0800 Subject: [PATCH] Add msvcp140_1.dll to list of import-time-check Windows DLLs Resolves https://github.com/tensorflow/tensorflow/issues/35036 For TensorFlow 2.1.0rc1, the TensorFlow team built Windows packages with Microsoft Visual Studio 2019 16.4, upgraded from Visual Studio 2017. As discovered in the issue linked above, this caused an import error for Windows TF Python whls, because the build upgrade pulled in an additional Visual C++ DLL dependency, `msvcp140_1.dll`, which can be found in the latest Visual C++ package for all Visual Studio releases since 2015 (https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads). I discovered the missing DLL by unpacking the two wheels for rc0 and rc1 and separately running `dumpbin /DEPENDENTS tensorflow_core/python/_pywrap_tensorflow_internal.pyd` (thanks to @yifeif for help with this!). In this change, I've updated the import-time checker to look for both `msvcp140_1.dll` and `msvcp140.dll` in a way that supports simple future additions to the list. PiperOrigin-RevId: 285476568 Change-Id: Ia9727e50801a4ddad1ea30653a74478fb7aee4e8 --- tensorflow/python/platform/self_check.py | 25 ++++++++++++++---------- tensorflow/tensorflow.bzl | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tensorflow/python/platform/self_check.py b/tensorflow/python/platform/self_check.py index 33aed306467..f6cf7705e13 100644 --- a/tensorflow/python/platform/self_check.py +++ b/tensorflow/python/platform/self_check.py @@ -42,17 +42,22 @@ def preload_check(): # we load the Python extension, so that we can raise an actionable error # message if they are not found. import ctypes # pylint: disable=g-import-not-at-top - if hasattr(build_info, "msvcp_dll_name"): - try: - ctypes.WinDLL(build_info.msvcp_dll_name) - except OSError: + if hasattr(build_info, "msvcp_dll_names"): + missing = [] + for dll_name in build_info.msvcp_dll_names.split(","): + try: + ctypes.WinDLL(dll_name) + except OSError: + missing.append(dll_name) + if missing: raise ImportError( - "Could not find %r. TensorFlow requires that this DLL be " - "installed in a directory that is named in your %%PATH%% " - "environment variable. You may install this DLL by downloading " - "Visual C++ 2015 Redistributable Update 3 from this URL: " - "https://www.microsoft.com/en-us/download/details.aspx?id=53587" - % build_info.msvcp_dll_name) + "Could not find the DLL(s) %r. TensorFlow requires that these DLLs " + "be installed in a directory that is named in your %%PATH%% " + "environment variable. You may install these DLLs by downloading " + '"Microsoft C++ Redistributable for Visual Studio 2015, 2017 and ' + '2019" for your platform from this URL: ' + "https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads" + % " or ".join(missing)) else: # TODO(mrry): Consider adding checks for the Linux and Mac OS X builds. pass diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index e55b67b3a27..fe653850d12 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -2382,7 +2382,7 @@ def tf_py_build_info_genrule(name, out, **kwargs): " --is_config_rocm " + if_rocm("True", "False") + " --key_value " + if_cuda(" cuda_version_number=$${TF_CUDA_VERSION:-} cudnn_version_number=$${TF_CUDNN_VERSION:-} ", "") + - if_windows(" msvcp_dll_name=msvcp140.dll ", "") + + if_windows(" msvcp_dll_names=msvcp140.dll,msvcp140_1.dll ", "") + if_windows_cuda(" ".join([ "nvcuda_dll_name=nvcuda.dll", "cudart_dll_name=cudart64_$$(echo $${TF_CUDA_VERSION:-} | sed \"s/\\.//\").dll",