Conda环境导入TensorFlow时DLL初始化失败错误求助
Hey there, let's break down what's going on here and fix that import error.
First off, the core issue is a clear mismatch in your setup: you installed the CPU-only TensorFlow but also have CUDA Toolkit v9.0 and cuDNN v7.1 configured—these dependencies are only required for GPU-enabled TensorFlow. The CPU version doesn't need (and actively conflicts with) CUDA-related libraries, which is almost certainly causing the import failure you're seeing.
Here's how to resolve this step by step:
Confirm your TensorFlow variant first
Run this command in your conda environment to double-check what you have installed:conda list tensorflowIf the package name is just
tensorflow, that's the CPU-only version. If it weretensorflow-gpu, you'd have the GPU variant (but it sounds like you intentionally installed the CPU build).Quick test to confirm the conflict
On Windows, open your command prompt, activate your conda environment, and run this to temporarily disable CUDA detection:set CUDA_VISIBLE_DEVICES=-1Now try importing TensorFlow again with
import tensorflow as tf. If this works, it confirms the CUDA environment is interfering with the CPU-only build.Permanent fixes based on your needs
If you don't need GPU support
Create a clean conda environment dedicated to CPU-only TensorFlow to avoid leftover CUDA conflicts:conda create -n tf_cpu python=3.6 conda activate tf_cpu # Install a CPU-only TensorFlow version compatible with Python 3.6 pip install tensorflow==1.12.0You can also uninstall CUDA Toolkit and cuDNN from your system if you don't plan to use GPU acceleration for any other tools.
If you actually want GPU support
You installed the wrong TensorFlow variant. Uninstall the CPU version and install the GPU-enabled one that matches your CUDA/cuDNN setup (TensorFlow 1.12.x to 1.14.x work perfectly with CUDA 9.0 + cuDNN 7.1 and Python 3.6):conda activate tensorflow_gpu pip uninstall tensorflow pip install tensorflow-gpu==1.13.1
Verify your fix
After adjusting your setup, import TensorFlow and run these checks to confirm everything works:import tensorflow as tf print(tf.__version__) # For GPU version, confirm GPU is detected: print(tf.test.is_gpu_available())
A quick side note: The official TensorFlow docs explicitly state that CUDA/cuDNN are not required for the CPU-only installation. It sounds like you might have mixed steps from the CPU and GPU installation guides, leading to this conflict.
内容的提问来源于stack exchange,提问作者Mario Ariyanto

