1# Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15 16"""Platform-specific code for checking the integrity of the TensorFlow build.""" 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21import os 22 23MSVCP_DLL_NAMES = "msvcp_dll_names" 24 25try: 26 from tensorflow.python.platform import build_info 27except ImportError: 28 raise ImportError("Could not import tensorflow. Do not import tensorflow " 29 "from its source directory; change directory to outside " 30 "the TensorFlow source tree, and relaunch your Python " 31 "interpreter from there.") 32 33 34def preload_check(): 35 """Raises an exception if the environment is not correctly configured. 36 37 Raises: 38 ImportError: If the check detects that the environment is not correctly 39 configured, and attempting to load the TensorFlow runtime will fail. 40 """ 41 if os.name == "nt": 42 # Attempt to load any DLLs that the Python extension depends on before 43 # we load the Python extension, so that we can raise an actionable error 44 # message if they are not found. 45 import ctypes # pylint: disable=g-import-not-at-top 46 if MSVCP_DLL_NAMES in build_info.build_info: 47 missing = [] 48 for dll_name in build_info.build_info[MSVCP_DLL_NAMES].split(","): 49 try: 50 ctypes.WinDLL(dll_name) 51 except OSError: 52 missing.append(dll_name) 53 if missing: 54 raise ImportError( 55 "Could not find the DLL(s) %r. TensorFlow requires that these DLLs " 56 "be installed in a directory that is named in your %%PATH%% " 57 "environment variable. You may install these DLLs by downloading " 58 '"Microsoft C++ Redistributable for Visual Studio 2015, 2017 and ' 59 '2019" for your platform from this URL: ' 60 "https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads" 61 % " or ".join(missing)) 62 else: 63 # TODO(mrry): Consider adding checks for the Linux and Mac OS X builds. 64 pass 65