Open jdemeyer opened 7 years ago
As discussed, it can't install a kernelspec that uses sys.executable from the Python it's installed with, so any kernelspec you install with the package will be dependent on the PATH. I prefer to have two steps that work reliably than one step that's flaky.
it can't install a kernelspec that uses sys.executable from the Python it's installed with
Of course it can. You can run arbitrary Python code in setup.py
. It won't work with wheels, but I think that's a minor issue which should not prevent easier installing with pip
.
Recent versions of pip install by building and caching a wheel, which can be reused for subsequent installations. So you can only run arbitrary code by deliberately preventing it from ever building wheels. That's an ugly hack, and given the advantages of wheels in general, I don't want to do that.
https://github.com/jupyter/jupyter_client/pull/235 allows having a static kernel.json
(with a sufficiently new jupyter):
> cat echo/kernel.json
{
"argv": ["python", "-m", "echo_kernel", "-f", "{connection_file}"],
"display_name": "Echo",
"language": "text"
}
Personally, I'm interested in absolutely minimal steps to get a kernel working, so like the prospect of not needed any echo_kernel/install.py
boilerplate, just using
jupyter kernelspec install ./echo/
.
However that's still a 2nd command, and harder to do after pip install echo_kernel
(if not sure where it stuck it).
Apparently https://github.com/ipython/ipykernel/pull/223 builds on that to create and install a kernel during pip install
, even with wheels (?). They do run python code to generate a kernel.json, but I think that's just to DRY some stuff, what I get out looks like it could be static content:
{
"display_name": "Python 2",
"language": "python",
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
]
}
And the dir gets installed by adding it to data_files
.
It seems that using data_files
is the standard way now (since notebook-5.3) to install nbextensions. See for example https://github.com/jupyter-widgets/ipywidgets/pull/1911
There are good reasons why this was done: when a package is installed using pip install
, it should "just work" without any additional manual steps.
By analogy, using data_files
for kernel specs should also become the standard way. And as explained in https://github.com/jupyter/echo_kernel/issues/3#issuecomment-305833260 this now works perfectly fine in wheels too.
@maartenbreddels
@cben @jdemeyer
https://github.com/jupyter/jupyter_client/pull/235 allows having a static kernel.json (with a sufficiently new jupyter)
Although as far as I can tell, a static kernel.json
does not allow for a relative path for the kernel code to be installed. If you try to specify anything other than a trivial current working directory, it fails. While there's no error when the jupyter kernelspec install
gets run, at runtime Jupyter will thrown exceptions because it cannot find the kernel.
If your directory structure has foo/bar/kernel.json
then the kernel source must be at the foo
level.
Is there any way to specify the location of the kernel (e.g., inside some source directory, to allow for Py packaging) which does not rely on customizing the PATH ?
Even if installing the kernel as part of the package installation were impossible (it isn't), the installation instructions in the README are incomplete since it says nowhere which other command to run to install the kernel. I had to additionally run python3 install.py
.
Moreover, installing the kernel manually says:
Installing Jupyter kernel spec
install.py:23: DeprecationWarning: replace is ignored. Installing a kernelspec always replaces an existing installation
KernelSpecManager().install_kernel_spec(td, 'echo', user=user, replace=True, prefix=prefix)
Basic usage should be as basic as possible.
Therefore, I think that a basic installation of the kernel should also install the kernel spec file such that the kernel is directly ready to use. I don't think we should put additional burden on the user to run
python -m echo_kernel.install
to actually install the kernel spec.