[英]How To Set Sources For Jupyter Notebooks
I've just bought a new computer, and can't remember/don't know how I had Jupyter notebooks set up on my old machine. 我刚买了一台新电脑,不记得/不知道如何在旧机器上安装Jupyter笔记本电脑。 Specifically, how do you tell Jupyter about sources. 具体来说,您如何告诉Jupyter有关来源。
If I have a conda environment called django, and I do source activate django
followed by jupyter notebook
, I end up with a notebook, but then when I do from django.http import HttpResponse
I get the error message 如果我有一个名为django的conda环境,并且我先进行了source activate django
然后执行了jupyter notebook
,则最终得到了一个笔记本,但是当我from django.http import HttpResponse
执行操作时from django.http import HttpResponse
我得到了错误消息
ModuleNotFoundError: No module named 'django'
Which is bizarre (I think), because Django is definitely installed in the Django environment. 我觉得这很奇怪,因为Django确实安装在Django环境中。
How do I set up my Jupyter notebooks so that they know about the various sources that I want them to know about? 如何设置Jupyter笔记本,以便他们了解我希望他们了解的各种来源?
It is very likely your conda environment django
doesn't have iPython Kernel installed which jupyter notebook needs. 您的conda环境django
很可能没有安装jupyter笔记本需要的iPython内核。 You can run jupyter notebook
without activating a conda environment as notebook allows you to select any conda environment with ipykernel
installed. 您可以在不激活jupyter notebook
环境的情况下运行jupyter notebook
,因为Notebook允许您选择安装了ipykernel
任何ipykernel
环境。
Try: 尝试:
source activate django
在终端中运行: source activate django
conda install ipykernel
在终端中运行: conda install ipykernel
source deactivate
在终端中运行: source deactivate
jupyter notebook
在终端中运行: jupyter notebook
django
for your kernel 为您的内核选择django
I create a kernel for each of my virtual environments. 我为每个虚拟环境创建一个内核。 On MacOS Jupyter kernels are located here $HOME/Library/Jupyter/kernels
. 在MacOS上,Jupyter内核位于$HOME/Library/Jupyter/kernels
。 Make sure ipykernel
is installed in your virtual env. 确保ipykernel
已安装在您的虚拟环境中。
So $HOME/Library/Jupyter/kernels/myenv/kernel.json
looks like: 因此$HOME/Library/Jupyter/kernels/myenv/kernel.json
如下所示:
{
"env": { "VIRTUAL_ENV": "/Users/<User>/<myenv>" },
"argv": [ "/Users/<User>/<myenv>/bin/python3", "-m", "ipykernel", "-f", "{connection_file}" ],
"display_name": "My Virtual Env",
"language": "python"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.