在anaconda虚拟环境中成功安装TensorFlow后还是出现ModuleNotFoundError: No module named 'tensorflow'
硬件:NVIDIA GeForce RTX 2070
软件:conda 4.12.0
cuda 11.1.74
cudnn 8.4.0
python 3.7.15
tensorflow 2.5.0
C:\Users\NiLujie>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Tue_Sep_15_19:12:04_Pacific_Daylight_Time_2020
Cuda compilation tools, release 11.1, V11.1.74
Build cuda_11.1.relgpu_drvr455TC455_06.29069683_0
C:\Users\NiLujie>set cuda
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
CUDA_PATH_V11_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
在环境中运行python时,import tensorflow as tf 没有问题
(tfcp37) C:\Users\NiLujie>python
Python 3.7.15 (default, Nov 24 2022, 18:44:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2022-12-17 22:12:55.486508: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cudart64_110.dll
>>>
在环境中打开xxx.py文件时出现报错,ModuleNotFoundError: No module named 'tensorflow'
(tfcp37) C:\Users\NiLujie>start.py
Traceback (most recent call last):
File "C:\Users\NiLujie\start.py", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
检查TensorFlow的安装情况