Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/platform/self_check.py: 48%
21 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
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# ==============================================================================
16"""Platform-specific code for checking the integrity of the TensorFlow build."""
17import ctypes
18import os
20MSVCP_DLL_NAMES = "msvcp_dll_names"
22try:
23 from tensorflow.python.platform import build_info
24except ImportError:
25 raise ImportError("Could not import tensorflow. Do not import tensorflow "
26 "from its source directory; change directory to outside "
27 "the TensorFlow source tree, and relaunch your Python "
28 "interpreter from there.")
31def preload_check():
32 """Raises an exception if the environment is not correctly configured.
34 Raises:
35 ImportError: If the check detects that the environment is not correctly
36 configured, and attempting to load the TensorFlow runtime will fail.
37 """
38 if os.name == "nt":
39 # Attempt to load any DLLs that the Python extension depends on before
40 # we load the Python extension, so that we can raise an actionable error
41 # message if they are not found.
42 if MSVCP_DLL_NAMES in build_info.build_info:
43 missing = []
44 for dll_name in build_info.build_info[MSVCP_DLL_NAMES].split(","):
45 try:
46 ctypes.WinDLL(dll_name)
47 except OSError:
48 missing.append(dll_name)
49 if missing:
50 raise ImportError(
51 "Could not find the DLL(s) %r. TensorFlow requires that these DLLs "
52 "be installed in a directory that is named in your %%PATH%% "
53 "environment variable. You may install these DLLs by downloading "
54 '"Microsoft C++ Redistributable for Visual Studio 2015, 2017 and '
55 '2019" for your platform from this URL: '
56 "https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads"
57 % " or ".join(missing))
58 else:
59 # Load a library that performs CPU feature guard checking. Doing this here
60 # as a preload check makes it more likely that we detect any CPU feature
61 # incompatibilities before we trigger them (which would typically result in
62 # SIGILL).
63 from tensorflow.python.platform import _pywrap_cpu_feature_guard
64 _pywrap_cpu_feature_guard.InfoAboutUnusedCPUFeatures()