解决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 分钟前
水晶光电发布 2026 半年报:归母净利润 5.24 亿元同比增长 4.73%
人工智能·能源
浩腾数字多媒体7 分钟前
如何判断专业电子留言厂家适配条件?
大数据·人工智能·python
阿里云大数据AI技术12 分钟前
从 Common Crawl 到可训练语料:用 EMR Serverless Daft 构建清洗、模型标注与向量化管线
人工智能·spark
jay神17 分钟前
27届计算机专业深度学习选题推荐
人工智能·深度学习·yolo·机器学习·计算机视觉
stuartevil19 分钟前
AI漫剧日更制作怎么做才不累
人工智能
大模型任我行21 分钟前
NUS:全模态感知驱动AI科学家
人工智能·语言模型·自然语言处理·论文笔记
weixin_4462608523 分钟前
G‑MARK:基于知识图谱的协同自动驾驶接地多智能体推理框架
人工智能·自动驾驶·知识图谱
天天进步201525 分钟前
Pixelle-Video 源码解析 #6:AI 文案生成流程:如何根据主题自动写解说词?
人工智能
章老师说30 分钟前
壬远 AI 网关 v0.4.0 正式发布:模型定价、RMB 配额与多 Key 路由,让企业级 AI 流量治理再进一步
人工智能·ai·开源·负载均衡·ai-native
luckystar513~34 分钟前
LLM那些事 03:Transformer 与注意力——聚光灯扫过每一个字
人工智能·深度学习·transformer