|
| 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.""" |
| 17 | +from __future__ import absolute_import |
| 18 | +from __future__ import division |
| 19 | +from __future__ import print_function |
| 20 | + |
| 21 | +import os |
| 22 | + |
| 23 | + |
| 24 | +def preload_check(): |
| 25 | + """Raises an exception if the environment is not correctly configured. |
| 26 | +
|
| 27 | + Raises: |
| 28 | + ImportError: If the check detects that the environment is not correctly |
| 29 | + configured, and attempting to load the TensorFlow runtime will fail. |
| 30 | + """ |
| 31 | + if os.name == "nt": |
| 32 | + # Attempt to load any DLLs that the Python extension depends on before |
| 33 | + # we load the Python extension, so that we can raise an actionable error |
| 34 | + # message if they are not found. |
| 35 | + import ctypes # pylint: disable=g-import-not-at-top |
| 36 | + try: |
| 37 | + ctypes.WinDLL("msvcp140.dll") |
| 38 | + except OSError: |
| 39 | + raise ImportError( |
| 40 | + "Could not find 'msvcp140.dll'. TensorFlow requires that this DLL be " |
| 41 | + "installed in a directory that is named in your %PATH% environment " |
| 42 | + "variable. You may install this DLL by downloading Visual C++ 2015 " |
| 43 | + "Redistributable Update 3 from this URL: " |
| 44 | + "https://www.microsoft.com/en-us/download/details.aspx?id=53587") |
| 45 | + # TODO(mrry): Add specific checks for GPU DLLs if build_info indicates |
| 46 | + # that this is a GPU build. |
| 47 | + else: |
| 48 | + # TODO(mrry): Consider adding checks for the Linux and Mac OS X builds. |
| 49 | + pass |
0 commit comments