如何在虚拟环境中放置自定义Jupyter内核? [英] How to place custom Jupyter kernels inside virtual environment?

查看:245
本文介绍了如何在虚拟环境中放置自定义Jupyter内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的Jupyter内核,该内核使用使用matplotlib样式表的自定义IPython配置文件运行IPython.

I have a custom Jupyter kernel which runs IPython using a custom IPython profile which uses a matplotlib stylesheet.

我知道我可以正常成功地运行此命令:

I know to run this successfully normally I would put:

  • 〜/.config/matplotlib/stylelib/

  • The matplotlib stylesheet in ~/.config/matplotlib/stylelib/

〜/.ipython/

The IPython profile in ~/.ipython/

〜/.jupyter/kernels/my_kernel/

The kernel json in ~/.jupyter/kernels/my_kernel/

但是我是作为在virtualenv中运行的较大程序的一部分来执行此操作的,如果我将上面的内容放在上面,则计算机上运行的任何笔记本服务器都将能够看到自定义内核,即使它在外部运行也是如此静脉我不是这个意思,因为我不希望我的程序干扰计算机上的其他笔记本.

But I am doing this as part of larger program which runs in a virtualenv, and if I put the things as above then any notebook server running on the computer will be able to see the custom kernels, even if it is running outside the venv. I don't what this because I don't want my program to interfere with other notebooks on the computer.

我认为我需要做的是将这些东西放在venv内等效的某个位置上,但是我不知道它们应该去哪里.有人知道他们会去哪里吗?还是这仅仅是IPython/Jupiter无法/不会做的事情?

I think what I need to do is put the things above somewhere equivalent inside the venv but I can't figure out where they should go. Doe anyone know where they would go? Or is this just a thing IPython/Jupiter can't/won't do?

可能值得一提的是,例如在样式表的情况下,我不想仅将其放在程序的工作目录中(这是matplotlib提供的一个选项).

It's probably worth mentioning that in the case of the stylesheet for example I don't want to just put it in the working directory of my program (which is one option matplotlib offers).

推荐答案

您可以将kernelspecs放在VIRTUAL_ENV/share/jupyter/kernels/中,如果笔记本服务器在该env中运行,它们将变为可用.通常,<sys.prefix>/share/jupyter/kernels包含在查找内核规范的路径中.

You can put kernelspecs in VIRTUAL_ENV/share/jupyter/kernels/ and they will be made available if the notebook server is running in that env. In general, <sys.prefix>/share/jupyter/kernels is included in the path to look for kernelspecs.

您可以看到Jupyter将看到的各个位置,还可以看到jupyter --paths的输出:

You can see the various locations Jupyter will look, you can see the output of jupyter --paths:

$ jupyter --paths

$ jupyter --paths

config:
    /Users/you/.jupyter
    /Users/you/env/etc/jupyter
    /usr/local/etc/jupyter
    /etc/jupyter
data:
    /Users/you/Library/Jupyter
    /Users/you/env/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter
runtime:
    /Users/you/Library/Jupyter/runtime

内核规范被视为数据文件,并且可以找到在data:下列出的任何目录中,在kernels子目录中,例如/usr/local/share/jupyter/kernels.

Kernelspecs are considered data files, and will be found in any of those directories listed under data:, in a kernels subdirectory, e.g. /usr/local/share/jupyter/kernels.

这篇关于如何在虚拟环境中放置自定义Jupyter内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆