Jupyter Notebook 无法识别 TensorFlow



我正在尝试在jupyter笔记本上运行tensorflow。我在张量流环境之外安装了 jupyter

sudo -H pip install jupyter

然后我通过以下方式激活了张量流环境

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(

编辑:我只是想澄清一下,张量流确实在我的机器上正确安装(例如,我可以在pycharm中使用它,以及当我从shell打开python时(。

编辑2:作为对@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

您需要按照以下步骤创建一个同时安装了 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

这行得通。

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

最新更新