我正在尝试在jupyter笔记本上运行tensorflow。我通过
在tensorflow环境之外安装了jupytersudo -H pip install jupyter
然后我通过
激活了tensorflow环境source ~/tensorflow/bin/activate
然后,当我在环境中时,我做了
pip install jupyter notebook
之后,我运行了jupyter笔记本,但是当我尝试导入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
答案 0 :(得分: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
有效。
答案 1 :(得分:0)
尝试从https://anaconda.org/anaconda/python安装anaconda,您将获得预先配置最常用的组件,最适合学习目的。安装后运行cmd> jupypter笔记本并按下输入。经过一些过程后,它会打开你的浏览器,你会看到你的笔记本。