Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip install should install kernel spec by default #3

Open
jdemeyer opened this issue Jan 19, 2017 · 7 comments
Open

pip install should install kernel spec by default #3

jdemeyer opened this issue Jan 19, 2017 · 7 comments

Comments

@jdemeyer
Copy link

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.

@takluyver
Copy link
Member

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.

@jdemeyer
Copy link
Author

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.

@takluyver
Copy link
Member

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.

@cben
Copy link

cben commented Jun 2, 2017

jupyter/jupyter_client#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 ipython/ipykernel#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.

@jdemeyer
Copy link
Author

It seems that using data_files is the standard way now (since notebook-5.3) to install nbextensions. See for example jupyter-widgets/ipywidgets#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 #3 (comment) this now works perfectly fine in wheels too.

@maartenbreddels

@ceteri
Copy link

ceteri commented Mar 2, 2024

@cben @jdemeyer

jupyter/jupyter_client#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 ?

@allefeld
Copy link

allefeld commented Mar 15, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants