无法导入TensorFlow GPU版本,动态库加载失败求助
Hey there, let’s work through this frustrating mismatch issue you’re facing with TensorFlow and CUDA. The core problem here is a version conflict between TensorFlow-gpu 2.0.0 and the mixed CUDA versions you’ve installed—let’s break this down and fix it step by step.
Why This Happens
TensorFlow-gpu has strict version requirements for CUDA and cuDNN. For TensorFlow-gpu 2.0.0, you need exactly CUDA Toolkit 10.0 and cuDNN 7.4.2. When you installed CUDA 10.1 afterward, it messed up the system’s ability to find the correct 10.0 libraries first.
Step-by-Step Fixes
1. Prioritize CUDA 10.0 in System Environment Variables
Your system is probably looking for CUDA libraries in the 10.1 path first. Let’s adjust that:
- Right-click "This PC" → "Properties" → "Advanced System Settings" → "Environment Variables"
- In the System Variables section, find the
Pathvariable and edit it - Locate the CUDA paths: move
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\binabove any CUDA 10.1-related paths - Do the same for
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvpif it exists - Save changes and restart PyCharm (or your entire computer to ensure the new paths take effect)
2. Verify cuDNN is Properly Matched to CUDA 10.0
Make sure you’re using the right cuDNN version for CUDA 10.0:
- Download cuDNN 7.4.2 (compatible with CUDA 10.0)
- Extract the zip file, then copy the contents of its
bin,include, andlib/x64folders into the corresponding folders in your CUDA 10.0 installation directory (e.g.,C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin)
3. Double-Check Your Virtual Environment Setup
- In PyCharm, confirm you’re using the correct
venvvirtual environment for your project - Open the terminal in PyCharm and run
pip show tensorflow-gputo confirm you have version 2.0.0 installed (no accidental upgrades or mismatches)
4. Optional: Uninstall CUDA 10.1 (If You Don’t Need It)
If you aren’t using CUDA 10.1 for other projects, uninstall it via Control Panel → "Programs and Features" → "NVIDIA CUDA Toolkit 10.1". This eliminates any chance of path conflicts entirely.
Verify the Fix
Restart PyCharm and run this test code to confirm everything works:
import tensorflow as tf print(f"TensorFlow version: {tf.__version__}") print(f"GPU available: {tf.test.is_gpu_available()}")
If it outputs 2.0.0 and True for GPU availability, you’re all set!
Your original error message for reference:
2020-02-28 09:31:24.742077: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\Users\Maximal\Documents\Python\PyCharm\Projekt1\venv\lib\site-packages\tensorflow\__init__.py", line 98, in <module> from tensorflow_core import * File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\Users\Maximal\Documents\Python\PyCharm\Projekt1\venv\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module> from tensorflow.python.tools import module_util as _module_util File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\Users\Maximal\Documents\Python\PyCharm\Projekt1\venv\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__ module = self._load() File "C:\Users\Maximal\Documents\Python\PyCharm\Projekt1\venv\lib\site-packages\tensorflow\__init__.py", line 44, in _load module = _importlib.import_module(self.__name__) File "C:\Users\Maximal\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "C:\Users\Maximal\Documents\Python\PyCharm\Projekt1\venv\lib\site-packages\tensorflow_core\python\__init__.py", line 52, in <module> from tensorflow.core.framework.graph_pb2 import * File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\Users\Maximal\Documents\Python\PyCharm\Projekt1\venv\lib\site-packages\tensorflow_core\core\framework\graph_pb2.py", line 7, in <module> from google.protobuf import descriptor as _descriptor File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\Users\Maximal\Documents\Python\PyCharm\Projekt1\venv\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module> from google.protobuf.pyext import _message File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs)
内容的提问来源于stack exchange,提问作者Daniel

