解决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了。

问题解决。

相关推荐
码上掘金3 分钟前
基于深度学习的行人计数与人群密度分析系统设计与实现
人工智能·深度学习
北京软秦科技有限公司8 分钟前
灌封胶耐候测试报告为何更依赖“AI报告审核”?IACheck如何提升长期环境可靠性判断精度
人工智能
程序员果子11 分钟前
Agent设计手册:四层架构、工程约束、框架选型
人工智能·agent·智能体·agent框架
2401_8322981015 分钟前
SaaS 到 Agent-as-a-Service——OpenClaw 生态爆发,开启企业数字化新时代
人工智能
AI产品测评官22 分钟前
2026年AI招聘架构深潜:多Agent协同如何打造主动出击智能体代表?
人工智能·架构
captain_AIouo27 分钟前
Captain AI:全阶段适配不同规模OZON商家
大数据·人工智能·经验分享·aigc
HyperAI超神经38 分钟前
在线教程丨支持600+语言,小米开源OmniVoice:仅需3-10秒参考音频实现语音克隆
人工智能·音频识别·语音生成
段一凡-华北理工大学39 分钟前
【高炉炼铁领域炉温监测、预警、调控智能体设计与应用】~系列文章14:时序数据处理:捕捉温度的脉搏
人工智能·高炉炼铁·工业智能体·炉温监测·炉温预警
情绪总是阴雨天~43 分钟前
提示词工程实战:金融行业 Prompt 设计与大模型应用
人工智能·金融·prompt
汽车仪器仪表相关领域44 分钟前
Kvaser Air Bridge Light HS:免配置工业级无线 CAN 桥接器,70 米稳定传输,移动设备与动态场景的 CAN 互联理想之选
人工智能·功能测试·安全·单元测试·汽车·可用性测试