Python3.5下已通过pip/Anaconda安装TensorFlow仍提示找不到模块错误
ImportError: No module named 'tensorflow' in Python 3.5 Hey there, let’s work through why your TensorFlow import is failing even after installing it with pip and Anaconda. I’ve hit this exact snag a handful of times, so here are the most reliable fixes to try:
1. Double-check you’re using the right Python environment
This is by far the most common culprit. You might have installed TensorFlow in one environment but be running your script in a totally different one.
- First, confirm which Python interpreter you’re invoking:
Note the path it outputs—this is the Python your script is using.which python3 # macOS/Linux where python3 # Windows - Next, verify where TensorFlow was installed:
- For pip: Run
pip3 show tensorflowand check theLocationfield. It should match thesite-packagesdirectory of the Python path you just noted. - For Anaconda: Run
conda info --envsto list all your environments, then make sure you’re activated in the right one withconda activate <your-env-name>. Then runconda list tensorflowto confirm it’s installed there.
- For pip: Run
2. Use the correct pip/conda for your environment
Mixing system-wide pip/conda with your Anaconda environment’s tools is an easy mistake to make.
- If you’re using Anaconda, always activate your environment first before installing:
conda activate your-env-name conda install tensorflow - If you prefer pip with Anaconda, use the pip that’s tied to your active environment (this avoids system pip conflicts):
Usingconda activate your-env-name python -m pip install tensorflowpython -m pipguarantees you’re using the pip associated with the Python you’re currently working with.
3. Install a TensorFlow version compatible with Python 3.5
Important heads-up: TensorFlow dropped support for Python 3.5 starting with version 2.0. So if you tried installing the latest TensorFlow, it won’t show up in your 3.5 environment. You need to install the last compatible version:
- With pip:
python -m pip install tensorflow==1.15 - With Anaconda:
conda config --add channels conda-forge # If conda can't find the package initially conda install tensorflow=1.15
4. Verify the installation actually worked
After installing, run this quick test in your terminal (make sure your environment is activated) to confirm TensorFlow is accessible:
python -c "import tensorflow as tf; print(tf.__version__)"
If this works, the problem is with how you’re running your script—like using the wrong interpreter in your IDE.
5. Fix IDE interpreter mismatch
If you’re using VS Code, PyCharm, or another IDE:
- VS Code: Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS), search for "Python: Select Interpreter", and pick the conda environment/Python path where you installed TensorFlow. - PyCharm: Go to
File > Settings > Project: [Your Project] > Python Interpreter, click the gear icon, select "Add", and choose the correct conda environment or Python executable.
Start with these steps in order—chances are it’s either an environment mix-up or an incompatible TensorFlow version for Python 3.5. Let me know if any of these get you up and running!
内容的提问来源于stack exchange,提问作者iffi

