解决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 小时前
智能商店+自主智能体APP 商业计划书
人工智能·机器人·ai-native
小猴子下山1231 小时前
无锡芯健细胞:赫尔曼疗法≠洗血
人工智能·精选
Henry-SAP1 小时前
SAP PP 从停工待料到精准排产
人工智能·云原生·sap·erp
大金SEO1 小时前
注册商标企业,在做GEO优化时应选用哪类媒体,才更易被AI采纳?
大数据·人工智能
ai小陈1 小时前
大模型推理显存不够怎么办?量化、KV Cache与CPU Offload优化实战
大数据·人工智能·ai·云计算·gpu算力
爱学堂IT分享1 小时前
网盘课程资源AI小王子Jay【2026最新】ComfyUI AI系统陪跑课
人工智能
2601_949950631 小时前
没有现成习题,试试AI再写出题
人工智能·小程序·刷题·练习·小程序推荐
干饭选手又困了�6861 小时前
AI 商品主图生成实操:从白底图到多规格物料交付全流程
人工智能
liukuang1101 小时前
2026中报对决:安踏借船出海,李宁自己造船
大数据·人工智能
minhuan1 小时前
拆解A2A大模型核心能力:详解场景化应用,构建智能交互、业务自动化完整应用方案25.8
人工智能·a2a·a2a应用实践·a2a智能体构建·a2a多智能体协同