【问题标题】:"No module" after setting up jupyter kernel设置 jupyter 内核后“无模块”
【发布时间】:2023-02-20 09:36:33
【问题描述】:

我使用 official instructions 安装了 tensorflow:

conda create -n tf-gpu tensorflow-gpu

如果我激活内核,我可以看到安装了 tensorflow。

conda activate tf-gpu
python3 -c 'import tensorflow as tf; print(tf.__version__)'

它返回以下内容。

2022-03-24 01:21:50.006341: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2.4.1

现在我想让 tf-gpu 被识别为 jupyter notebook 中的内核。

conda deactivate tf-gpu
python -m ipykernel install --user --name=tf-gpu

但是,当我启动 jupyter 笔记本时

jupyter notebook

创建的 tf-gpu notebook 没有按预期工作。

import tensorflow

返回以下错误

ModuleNotFoundError: No module named 'tensorflow'

为什么包裹没有被识别?

【问题讨论】:

    标签: python tensorflow import jupyter-notebook anaconda


    【解决方案1】:

    您需要为此环境创建一个新内核,并从 jupyter notebook 中选择内核,如下所示:

    conda activate env_name
    pip install ipykernel --user
    python -m ipykernel install --user --name env_name --display-name env_name
    

    然后打开笔记本>>点击内核>>更改内核>>选择内核。

    让我们知道问题是否仍然存在。谢谢!

    【讨论】:

      【解决方案2】:

      或者你也可以在安装后使用ipython kernel代替ipykernel,如下图:

      ipython kernel install --user --name env_name --display-name env_name

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-30
        • 2018-09-07
        • 2023-02-21
        • 1970-01-01
        • 2016-03-25
        • 2022-10-19
        • 1970-01-01
        • 2020-08-06
        相关资源
        最近更新 更多