解决conda环境下import TensorFlow失败的问题

问题描述

安装了anaconda的电脑,新建了一个名叫deeplearning的环境,在该环境下已经成功安装了tensorflow。

于是在终端打开python并执行代码

python 复制代码
import tensorflow as tf
print(1)

除了提示

shell 复制代码
2024-02-27 21:50:00.801427: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used.
2024-02-27 21:50:00.838675: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-02-27 21:50:00.838709: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-02-27 21:50:00.839681: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-02-27 21:50:00.845214: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used.
2024-02-27 21:50:00.845380: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-02-27 21:50:01.529134: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
1

错误提示是代表没有安装TensorRT,暂时忽略,可以看出已经打印了1,已经安装成功。

但是运行juypter-notebook后,会提示

shell 复制代码
ModuleNotFoundError: No module named 'tensorflow'

原因

在新建环境下,没有安装juypter-notebook,导致运行的juypter-notebook实际上仍然是base环境下的,因此失败

解决

shell 复制代码
conda activate deeplearning
conda install nb_conda

这样就在deeplearning安装了juypter-notebook了。

问题解决。

相关推荐
zhaodiandiandian1 天前
AI 时代的就业变革:在挑战中寻找新机遇
人工智能
FY_20181 天前
SubprocVecEnv 原理、详细使用方法
人工智能·python·机器学习
yiersansiwu123d1 天前
智能向善:人工智能伦理治理的中国实践与未来路径
人工智能
qq_348231851 天前
如何搭建AI知识库
人工智能
AI弟1 天前
推荐系统:带你走进推荐之路(二)
人工智能·python·深度学习·面试·推荐算法
Julian.zhou1 天前
AI架构新范式:告别“短期记忆”,迎接能思考、会规划的智能体时代
人工智能·ai·架构·未来趋势
谈笑也风生1 天前
浅谈:被称为新基建的区块链(六)
人工智能·区块链
新华经济1 天前
正荣激光焊接机:破解中小型制造场景激光焊接精度与效率困局
大数据·人工智能·制造
永霖光电_UVLED1 天前
科锐LED与SANlight携手合作园艺照明
人工智能
不错就是对1 天前
mmdetection - Linux环境搭建
图像处理·人工智能·python·深度学习·计算机视觉