paulovn / sparql-kernel

A Jupyter kernel to launch queries against SPARQL endpoints
BSD 3-Clause "New" or "Revised" License
98 stars 17 forks source link

Notebook examples are not working #33

Closed vemonet closed 5 years ago

vemonet commented 5 years ago

Hi,

I am trying to run the examples in a Jupyter Notebook (itself running in Docker): https://github.com/paulovn/sparql-kernel/blob/master/examples/sparql-vanGogh.ipynb Running Jupyter using Docker:

docker run -it -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes -v $PWD/work:/home/jovyan/work jupyter/datascience-notebook:latest

The example notebook is not working out of the box (no pip install, no import, so I guess you did them beside of the notebook)

So I tried to run the following commands from the README in the Notebook:

!pip install sparqlkernel
!jupyter sparqlkernel install --user

This block is executing fine, with the pip install working great, and the jupyter sparqlkernel install returning:

[SparqlKernelInstall] Installing SPARQL kernel
[SparqlKernelInstall] Installing kernel spec
[SparqlKernelInstall] Removing existing kernelspec in /home/jovyan/.local/share/jupyter/kernels/sparql
[SparqlKernelInstall] Installed kernelspec sparql in /home/jovyan/.local/share/jupyter/kernels/sparql
[SparqlKernelInstall] Installed into /home/jovyan/.local/share/jupyter/kernels/sparql
[SparqlKernelInstall] Installing CSS
[SparqlKernelInstall] Installing CSS into /home/jovyan/.jupyter/custom

But when I run the first block I get the following error: UsageError: Line magic function%endpointnot found.

So I guess that the sparql kernel is not properly installed/imported in Jupyter

I also tried to run those commands through docker exec my_container jupyter sparqlkernel install --user but, still not recognizing the magic lines

Do you know how to have this sparqlkernel running? Or is it any comprehensive example of a running one?

paulovn commented 5 years ago

Hi. As you correctly guessed, to run the notebook in Jupyter it is first necessary to have the kernel installed into Jupyter, otherwise it won't work. In fact, if I try to run the same docker container as you (jupyter/datascience-notebook:latest), when I go to the launcher tab in JupyterLab I see the kernels for Python, Julia and R, but obviously not for SPARQL, since it has not been installed yet. If I then try to open the example notebook, it complains that it cannot find a suitable kernel.

The solution is, as you say, to follow the README and install the kernel by doing

 pip install sparqlkernel
 jupyter sparqlkernel install --user

Since you used a ! prefix, I guess you did that within the notebook, and you were using a Python kernel. So once that was made, the kernel should be available inside the container ... but that notebook was already using the previous (Python) kernel, so it would still not work. At that stage you can switch the kernel in the notebook: go to the upper right where the kernel name is printed (probably Python), click on it and you should be able to change it to the SPARQL kernel, then it would work,

Another possibility is to install the kernel before opening the notebook, perhaps by using a terminal window in the JupyterLab launcher. The use of docker exec on the running container as you propose should also work -- but again it will take effect only on the notebooks you open after installation.

vemonet commented 5 years ago

Hi! Thanks a lot, I am not really experimented with Jupyter Notebooks, this was my mistake

go to the upper right where the kernel name is printed It was what I missed, it is now working with Van Gogh example, thanks a lot!

To make this working out of the box it depends how we would approach the issue

Thanks a lot for the helps and the kernel! It is ideal for SPARQL querying

paulovn commented 5 years ago

The Dockerfile approach is straightforward:

FROM jupyter/datascience-notebook

RUN pip install sparqlkernel && jupyter sparqlkernel install --user

If you use that Dockerfile to build a new image by e.g.

docker build . -t jupyter/datascience-notebook-sparql

then you can just launch that new image instead of the original one, and the kernel will be available from the start.