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

问题解决。

相关推荐
罗西的思考1 小时前
AI 时代的 “房谋杜断”:如何培养能力、品味与判断力
人工智能·算法·机器学习
字节跳动视频云技术团队2 小时前
720P 直升 8K,解密 2026 抖音美好奇妙夜巨幕超分黑科技
人工智能·音视频开发
打工仔折腾 AI2 小时前
在 Ubuntu ARM64 部署 Q1 V3.0 MuJoCo 模型:加载、单步推理与执行器响应解析
linux·运维·人工智能·python·深度学习·ubuntu·性能优化
逐米时代2 小时前
从试点验证到协同深化:制造业AI转型三年路线图设计方法
人工智能
GlobalInfo2 小时前
全球及中国风电叶片检测机器人行业研究报告(2026版):市场现状、行业前景与占有率分析
运维·网络·人工智能·机器人
stormzhangV3 小时前
AI 越强,失业越严重
人工智能·aigc
夏文强4 小时前
Rerank 与混合检索:怎么让 RAG 从「能用」变成「好用」
人工智能·大模型·向量数据库·rag·检索增强生成
救救孩子把4 小时前
AI面试八股文-23_23-Agent可观测性与生产监控面试题
人工智能·面试·职场和发展·agent·langsmith·langfuase
IT_陈寒4 小时前
Java静态变量初始化坑得我头皮发麻
前端·人工智能·后端
知行产研4 小时前
白马山领跑、南山矿扩编 31 台,安徽露天矿无人驾驶进入规模化阶段
人工智能