【问题标题】:jupyter notebook does not recognize tensorflowjupyter notebook 无法识别张量流
【发布时间】:2017-11-12 08:03:01
【问题描述】:

我正在尝试在 jupyter notebook 上运行 tensorflow。我通过这样做在 tensorflow 环境之外安装了 jupyter

sudo -H pip install jupyter

然后我通过

激活了tensorflow环境
source ~/tensorflow/bin/activate 

然后,当我在环境中时,我做到了

pip install jupyter notebook

之后,我运行了jupyter notebook,但是当我尝试导入tensorflow时,出现以下错误:

ImportError: No module named tensorflow

我检查了jupyter是否通过运行识别环境

which jupyter

得到了

/usr/local/bin/jupyter

这意味着它没有识别环境。如何强制 jupyter 识别环境? (正如我提到的,我也确实在环境中安装了 jupyter)

编辑:我只是想澄清一下 tensorflow 确实已正确安装在我的机器上(例如,我可以在 pycharm 中使用它,也可以在我刚从 shell 打开 python 时使用它)。

Edit2:作为对@hek2mgl 评论的回应,这是我得到的:

username@blabla:~$ source ~/tensorflow/bin/activate 
(tensorflow) username@blabla:~$ pip install jupyter
(tensorflow) username@blabla:~$ which jupyter
/usr/local/bin/jupyter
(tensorflow) username@blabla:~$ hash -d
hits    command
   1    /usr/bin/which
   1    /home/local/bla/username/tensorflow/bin/pip
(tensorflow) username@blabla:~$ which jupyter
/usr/local/bin/jupyter

【问题讨论】:

  • 你需要在同一个virtualenv中安装tensorflow和jupyter
  • 谢谢。当我在环境中时,我运行“pip install jupyter notebook”,但它不起作用。我需要做其他事情吗?
  • 运行hash -d。然后再次运行which jupyter
  • @hek2mgl,谢谢。我添加了这一行,并编辑了问题以显示我得到了什么。
  • 激活命令后运行pip install jupyter 然后再次运行hash -d

标签: python linux ubuntu tensorflow jupyter


【解决方案1】:

您需要按照以下步骤创建一个安装了 tensorflow 和 jupyter 的新 virtualenv:

#!/bin/bash
virtualenv -ppython3 my_env
source my_env/bin/activate
pip install tensorflow jupyter
jupyter notebook

在 Web GUI 中创建一个新的 Python3 笔记本并运行:

import tensorflow

这行得通。

【讨论】:

  • 非常感谢!有效。只是为了确保,如果我想用 gpu 使用 tensorflow(就像我在问题中提到的 tensorflow 环境中那样),我应该运行 pip install tensorflow-gpu jupyter 而不是 pip install tensorflow jupyter?
  • 是的,当然。只要确保所有东西都安装在同一个 virtualenv 中
【解决方案2】:

尝试从https://anaconda.org/anaconda/python 安装 anaconda,您将获得预配置的最常用的组件,并且最适合学习目的。安装后运行 cmd> jupypter notebook 并回车。经过一些过程,它将打开您的浏览器,您将看到您的笔记本。

【讨论】:

  • 嗨@SarmadMahar,tensorflow 不是anaconda 的一部分,所以我不得不单独安装它。我可以打开 jupyter notebook 并导入 numpy 等常用的东西,但它无法识别我的 tensorflow 安装。
  • 然后使用 pip install tensorflow jupyter
猜你喜欢
  • 2020-05-16
  • 2021-02-09
  • 2019-02-14
  • 1970-01-01
  • 2021-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多