在 conda jupyter lab notebook 中使用 tensorflow 的问题

Issues using tensorflow inside conda jupyter lab notebook

我在尝试设置一个能够使用 tensorflow 和 keras 的 jupyter 实验室时遇到了 运行 问题。

tl;dr 我已经尝试了多种不同的方法来使用 cmd(我在 windows)将它安装在 conda 上的虚拟环境中,以及使用 GUI 来安装它。在所有情况下,我都可以将 tensorflow 导入 python,但是当我在浏览器中打开 jupyter lab notebook 时,它永远找不到模块。

长版: 打开 Anconda 并在基本环境中启动 cmd。 cd 到我想要设置环境的地方,基本上在 OneDrive 的一大堆子目录中,因为这是我在大学时使用的。

(base) C:\Users\adamp>cd Onedrive - maynooth university/year 4/cs401/assignments/ass2

创建 conda 虚拟环境:conda create -n cs401_ass2 --yes

然后使用以下方式激活它:conda activate cs401_ass2

所以现在我在 venv 里面。

使用conda install tensorflow

安装tensorflow

接受所有包裹等...

现在它已安装,我可以使用 python 检查它。输入 python

然后import tensorflow as tf

它没有抛出任何错误,据我所知,这意味着它安装正确....

所以现在我退出 python,returns 我进入我的虚拟环境。然后我想通过输入 jupyter lab

来启动 jupyter lab

它在我的浏览器中打开 (chrome)

我打开一个新的 iPy 笔记本

键入 import tensorflow as tf,现在 returns 它没有模块...

错误信息 ==> https://i.stack.imgur.com/JLFTP.png

帮助我 Obiwan....你是我唯一的希望

你还没有安装 jupyter-lab 到这个环境,所以 Windows 选择了次优的选择:它在其 PATH 上的另一个 JupyterLab。问题是,在那个环境中 tensorflow 没有安装 - 因此出现错误。

解决方案:

  • 激活环境:conda activate cs401_ass2
  • 安装 JupyterLab:conda install -c conda-forge jupyterlab

您真诚的,欧比万。