无法在Jupyter中导入Keras [英] Unable to import Keras in Jupyter
问题描述
因此,我使用python 3和jupyter(使用pip)设置了虚拟局域网.一切正常,但如果我尝试导入keras,它将无法在jupyter中工作,并告知未找到模块.但是,如果我在终端中执行相同的文件(python3 test.py),就可以正常工作.
So I set up my virtual lan with python 3 and jupyter (with pip). All works fine but if I try to import keras it will not work in jupyter and tells module not found. But if I execute the same file (python3 test.py) in the terminal it works fine.
which jupyter
/usr/local/bin/jupyter
which python3
/Users/niro273/Desktop/xcorp/bin/python3
如果我执行pip3 list
,这些就是结果.
If I do a pip3 list
these are the results.
jupyter (1.0.0)
jupyter-client (5.1.0)
jupyter-console (5.2.0)
jupyter-core (4.3.0)
Keras (2.0.8)
注意-我也在虚拟环境中安装了jupyter(pip3 install jupyter).因此,我是否必须切换木贼执行路径?不胜感激.
Note- I have installed jupyter (pip3 install jupyter) inside the virtual env too. So should I have to switch the juypter execution path ? Would appreciate any guidance.
推荐答案
都是Keras& Jupyter必须安装在您的虚拟环境中;然后,您应该在激活虚拟环境后启动Jupyter(在这种情况下,which jupyter
应该指向虚拟环境中的其他位置):
Both Keras & Jupyter must be installed inside your virtual environment; then, you should start Jupyter after activating your virtual env (in which case which jupyter
should point to a different location inside your virtual env):
$ which jupyter
/usr/local/bin/jupyter
$ virtualenv /venv/foo
$ source /venv/foo/bin/activate
$ (foo) pip3 install jupyter
$ (foo) which jupyter
/venv/foo/bin/jupyter
$ (foo) pip3 install keras
$ (foo) jupyter notebook
当然还有其他方法(例如安装另一个内核,指向foo
虚拟环境中的Python可执行文件),但是我发现上述方法更快,更轻松,至少对于Keras而言.
There are certainly other ways (e.g. to install a different kernel in your main Jupyter installation pointing to the Python executable in your foo
virtual environment), but I have found the above way to be quicker and more hassle-free, at least for Keras...
这篇关于无法在Jupyter中导入Keras的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!