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

问题解决。

相关推荐
zhangfeng113310 小时前
workbuddy 结合deepseekv4-flash 安装打印机 hp laster jet 3050
人工智能·workbuddy
爱看科技10 小时前
三星提速开启AI转型,英伟达/WIMI微美全息推进AI算力建设需求持续旺盛
人工智能
dog25010 小时前
信号权重和流分类的对数规律
人工智能·分类·数据挖掘
道一云黑板报10 小时前
告别提示词工程:为什么“循环工程”才是 AI 编程的未来?
人工智能·驱动开发·软件工程·ai编程
实在智能RPA10 小时前
大模型驱动航班规划实战:2026年企业级Agent重塑航空业调度逻辑
人工智能·ai
叫我:松哥10 小时前
基于Python的共享单车租赁数据分析与预测系统,技术栈flask+boostrap+随机森林+XGBoost
人工智能·python·深度学习·算法·随机森林·数据分析·flask
米小虾11 小时前
2026年6月AI大模型全景报告:GPT-5.6、Claude Opus 4.8、Gemini 3.5,中美AI三足鼎立谁主沉浮?
人工智能
米小虾11 小时前
AI Agent从Demo到生产:2026年主流Agent开发框架全景对比与实战选型指南
人工智能·agent
Sam092711 小时前
Agent 如何节省 Token 成本:从 Prompt 到工程监控的系统化优化指南
人工智能·ai
拓朗工控11 小时前
边缘计算对工控机性能要求有多高?
人工智能·边缘计算·工控机·工业电脑