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

问题解决。

相关推荐
Csvn17 小时前
AI 编程提效核心技巧(直接复制套用,大幅减少手写代码时间)
人工智能
delishcomcn17 小时前
预见性切割:机器学习如何提前预警碳带分切机的报废风险
人工智能·机器学习
拧AI螺丝17 小时前
你往 AI 里装的那些 skill,打开看过一眼吗?
人工智能·agent
学究天人17 小时前
数学星球:等价性(第1-4章)
人工智能
AI科技星17 小时前
公理化数学化学|48小时确权终稿(完整投产包)
人工智能·数学·算法·重构·拓扑学·乖乖数学·全域数学
程序员契奇17 小时前
Tools工具使用
人工智能·后端
小林ixn17 小时前
从“酸辣土豆丝”到“马铃薯做法”:手把手教你用 RAG 实现语义搜索
人工智能·llm
这张生成的图像能检测吗17 小时前
(论文速读)CWNet:用于微光图像增强的因果小波网络
图像处理·人工智能·深度学习·机器学习·低照度图像增强
睿智的羊17 小时前
Cove API 的 RAG 模块拆解:一套面向 Agent 的可组合知识检索工具体系
人工智能
love530love17 小时前
AI Agent + 本地 ComfyUI 无头模式实战:关闭 IDE 后 AI 独立重启并完成图文生成
ide·人工智能·windows·python·音视频·agent·devops