我已经用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
现在,当我在命令行中运行以下命令时,一切正常:
activate keras
python
import tensorflow
import keras
from keras.datasets import mnist
但是,当我使用 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'
但是为 tensorflow 导入没有错误。
然后我卸载了 tensorflow,并使用 conda install 重新安装了它:
conda install tensorflow
现在,当我运行 jupyter 时,我在 tensorflow 行上也遇到了同样的错误。
如何让 jupyter 处理使用 conda 安装的软件包?
附加信息:我从命令行和 jupyter 运行 sys.executable,并且都指向相同的路径:
'C:\\sw\\Anaconda3\\envs\\tensorflow\\python.exe'
这看起来像是最近的一个问题,我在https://github.com/jupyter/jupyter/issues/245 找到了一个类似的报告 ,但是我不太明白解决办法。有人可以帮忙吗?
最佳答案
ipykernel必须和环境 Hook ,jupyter才能使用。
以下安装过程有效:
conda create -n keras python=3.5 ipykernel
activate keras
python -m ipykernel install --user --name keras
jupyter notebook
现在,如果我在 jupyter notebook 中调用 sys.executable,它会打印访问可执行文件的正确环境。
关于python - conda 安装的软件包不适用于 jupyter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45693802/