已在Visual Studio 2017安装tensorflow(1.6.0)仍报错:No module named 'tensorflow'求助
Hey there, let's work through why you're hitting that "No module named 'tensorflow'" error in VS2017 even after installing TensorFlow 1.6.0. Below are the most common fixes to try, step by step:
Verify your Python environment matches where TensorFlow is installed
VS2017 can handle multiple Python environments (system Python, virtual environments, Anaconda, etc.), so it's easy to accidentally use the wrong one. Here's how to check:- Right-click your project in VS2017 → Properties → Python Environment.
- Make sure the selected interpreter is the exact one you installed TensorFlow into. For example, if you used
pipwith your system Python, it might look likeC:\Python36\python.exe(TensorFlow 1.6 works best with Python 3.5-3.7). - Double-check by opening the Python Interactive window in VS, then run:
Compare this path to the one you used when runningimport sys; print(sys.executable)pip install tensorflow==1.6.0. If they don't match, switch to the correct environment in the project properties.
Confirm TensorFlow is actually installed in your target environment
Sometimes installations can fail silently, or you might have installed it in a different environment without realizing.- Open Command Prompt, navigate to the folder of your project's Python interpreter (e.g.,
cd C:\Python36). - Run
pip listand look fortensorflow==1.6.0(ortensorflow-gpu==1.6.0if you're using the GPU version). - If it's missing, install it directly into this environment with:
Note: For GPU support, you'll also need CUDA 9.0 and cuDNN 7.0 installed on your system—TensorFlow 1.6 relies on these specific versions.pip install tensorflow==1.6.0
- Open Command Prompt, navigate to the folder of your project's Python interpreter (e.g.,
Refresh VS2017's environment cache
VS sometimes caches outdated environment information, which can make it miss newly installed packages.- Close and restart VS2017 completely.
- Reopen your project, then go to the Python Environments window (View → Other Windows → Python Environments) and click the Refresh button to update the list of installed packages.
Check for virtual environment misconfiguration
If you're using a virtual environment for your project:- Ensure you activated the virtual environment before installing TensorFlow (e.g.,
venv\Scripts\activateon Windows). - In VS2017, make sure your project is pointing to the virtual environment's Python interpreter (usually at
your-project-folder\venv\Scripts\python.exe).
- Ensure you activated the virtual environment before installing TensorFlow (e.g.,
Fix permission-related installation issues
If you installed TensorFlow without administrator permissions, some files might not have been installed correctly. Try this:- Open Command Prompt as an administrator.
- Navigate to your target Python interpreter's folder, then re-run the install command:
pip install tensorflow==1.6.0
内容的提问来源于stack exchange,提问作者Sa Ra

