conda 安装的软件包不适用于 jupyter

R71*_*R71 5 python python-3.x conda jupyter jupyter-notebook

我用pip install安装了tensorflow,用conda install安装了keras:(我的python3安装在Anaconda3下)

conda create -n keras python=3.5
activate keras
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl
conda install --channel https://conda.anaconda.org/conda-forge keras
Run Code Online (Sandbox Code Playgroud)

现在,当我在命令行中运行以下命令时,一切正常:

activate keras
python
import tensorflow
import keras
from keras.datasets import mnist
Run Code Online (Sandbox Code Playgroud)

但是,当我使用 jupyter 运行相同的命令时,在 keras 导入行上出现错误:

activate keras
jupyter notebook
# now open a python3 notebook
# and enter the above commands in it
# and run

ImportError: No module named 'keras'
Run Code Online (Sandbox Code Playgroud)

但是 tensorflow 的导入没有给出错误。

然后我卸载了 tensorflow,并使用 conda install 重新安装了它:

conda install tensorflow
Run Code Online (Sandbox Code Playgroud)

现在,当我运行 jupyter 时,我在 tensorflow 线上也遇到了同样的错误。

如何让 jupyter 处理使用 conda 安装的软件包?

附加信息:我从命令行和 jupyter 运行 sys.executable,并且都指向相同的路径:

'C:\\sw\\Anaconda3\\envs\\tensorflow\\python.exe'
Run Code Online (Sandbox Code Playgroud)

看起来是最近的问题,我在https://github.com/jupyter/jupyter/issues/245找到了类似的报告,但我不太明白解决方案。有人可以帮忙吗?

R71*_*R71 5

我在http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for- different-environments 找到了答案

ipykernel必须链接到环境,然后jupyter才能使用它。

以下安装过程有效:

conda create -n keras python=3.5 ipykernel
activate keras
python -m ipykernel install --user --name keras
jupyter notebook
Run Code Online (Sandbox Code Playgroud)

现在,如果我在 jupyter 笔记本中调用 sys.executable,它会打印访问可执行文件的正确环境。