如何为 Jupyter Notebooks 设置源
How To Set Sources For Jupyter Notebooks
我刚买了一台新电脑,remember/don不知道我是如何在我的旧电脑上设置 Jupyter notebooks 的。具体来说,你如何告诉 Jupyter 有关来源的信息。
如果我有一个名为 django 的 conda 环境,并且我执行 source activate django
,然后执行 jupyter notebook
,我最终得到一个笔记本,但是当我执行 from django.http import HttpResponse
时,我收到错误消息
ModuleNotFoundError: No module named 'django'
这很奇怪(我认为),因为 Django 肯定安装在 Django 环境中。
如何设置我的 Jupyter notebooks 以便它们知道我想让它们知道的各种来源?
很可能您的 conda 环境 django
没有安装 jupyter notebook 需要的 iPython 内核。您可以 运行 jupyter notebook
而无需激活 conda 环境,因为笔记本允许您 select 安装了 ipykernel
的任何 conda 环境。
尝试:
- 运行 在终端中:
source activate django
- 运行 在终端中:
conda install ipykernel
- 运行 在终端中:
source deactivate
- 运行 在终端中:
jupyter notebook
- select
django
适用于您的内核
我为每个虚拟环境创建了一个内核。在 MacOS 上,Jupyter 内核位于此处 $HOME/Library/Jupyter/kernels
。确保 ipykernel
安装在你的虚拟环境中。
所以 $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"
}
找到答案here。
source activate django
conda install ipykernal
python -m ipykernel install --user --name django --display-name "Python (Django)"
我刚买了一台新电脑,remember/don不知道我是如何在我的旧电脑上设置 Jupyter notebooks 的。具体来说,你如何告诉 Jupyter 有关来源的信息。
如果我有一个名为 django 的 conda 环境,并且我执行 source activate django
,然后执行 jupyter notebook
,我最终得到一个笔记本,但是当我执行 from django.http import HttpResponse
时,我收到错误消息
ModuleNotFoundError: No module named 'django'
这很奇怪(我认为),因为 Django 肯定安装在 Django 环境中。
如何设置我的 Jupyter notebooks 以便它们知道我想让它们知道的各种来源?
很可能您的 conda 环境 django
没有安装 jupyter notebook 需要的 iPython 内核。您可以 运行 jupyter notebook
而无需激活 conda 环境,因为笔记本允许您 select 安装了 ipykernel
的任何 conda 环境。
尝试:
- 运行 在终端中:
source activate django
- 运行 在终端中:
conda install ipykernel
- 运行 在终端中:
source deactivate
- 运行 在终端中:
jupyter notebook
- select
django
适用于您的内核
我为每个虚拟环境创建了一个内核。在 MacOS 上,Jupyter 内核位于此处 $HOME/Library/Jupyter/kernels
。确保 ipykernel
安装在你的虚拟环境中。
所以 $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"
}
找到答案here。
source activate django
conda install ipykernal
python -m ipykernel install --user --name django --display-name "Python (Django)"