TensorFlow安装正常但导入时报错:ImportError: No module named '_pywrap_tensorflow_internal'
Hey there, let's work through this TensorFlow import error you're hitting. You mentioned you tried both Anaconda virtual environments and a direct Python install (using Python 3.5.3 on Windows), but importing TensorFlow throws an error. Let's break down actionable fixes step by step:
1. Double-check your active environment (Anaconda users)
It’s easy to accidentally use the global Python instead of your virtual environment. Here’s how to confirm:
- Run
conda info --envsto list all your Anaconda environments. - Activate your TensorFlow-specific env with
conda activate [your-env-name](replace the placeholder with your actual env name). - Verify you’re using the right Python executable by running
where python—the path should point to your Anaconda env’spython.exe, not the global Windows or Python installation.
2. Install a TensorFlow version compatible with Python 3.5
Newer TensorFlow versions (2.x+) don’t support Python 3.5 anymore—this is a super common gotcha! Reinstall a compatible version:
- In your active terminal/env, run:
pip install tensorflow==1.15 - After installation, run
pip listto confirm TensorFlow 1.15 appears in the package list.
3. Fix missing Microsoft Visual C++ Redistributables
TensorFlow on Windows depends on specific system libraries. If you’re seeing a "DLL load failed" error, this is almost certainly the issue:
- Install the Microsoft Visual C++ 2015 Redistributable Update 3 (both x86 and x64 versions—even if you have 64-bit Windows, some components require the x86 version).
- Restart your computer after installation to ensure the libraries are loaded properly.
4. Clean up conflicting installations
If you installed TensorFlow both globally and in an Anaconda env, leftover files can cause conflicts. Do a clean reinstall:
- Uninstall TensorFlow from all locations:
- Global Python: Run
pip uninstall tensorflow - Anaconda env: Activate the env, then run
pip uninstall tensorfloworconda remove tensorflow
- Global Python: Run
- Create a fresh Anaconda env for TensorFlow:
conda create -n tf-clean python=3.5 conda activate tf-clean pip install tensorflow==1.15
5. Test in a fresh session
Leftover Python processes or cached modules can sometimes cause weird import issues. Close all open terminals, open a new one, activate your env (if using Anaconda), then run python and try import tensorflow again.
If you can share the full traceback of your error (the complete "Traceback (most recent call..." text), we can narrow this down even further—different error messages point to specific fixes!
内容的提问来源于stack exchange,提问作者Shrikant Prabhu

