Notebook Not Creating Output File

I am trying to understand how Notebooks work so I am using the example in “Notebook Writing Guide” to facilitate that learning. I have followed the procedure or at least think I did but I am experiencing an Error when trying to execute the Notebook in the Losant environment. In the local Jupyter environment I can see the “Histogram” built from the test data that I generated from the losant device. So I think that part is working correctly. I have then used the “Save and Checkpoint” option to create the .ipynb file. After that I used the “Download As” option and choose the "Notebook (.ipynb) option. I then created the Losant Notebook and configured the Input, Output, and downloaded the previously saved .ipynb file. After executing I am receiving an error. I have included a few files to help debug.Losant%20NB%20Error

Here is the result.log file contents

[NbConvertApp] Converting notebook /tmp/input.ipynb to notebook
Traceback (most recent call last):
File “/opt/conda/bin/jupyter-nbconvert”, line 10, in
sys.exit(main())
File “/opt/conda/lib/python3.7/site-packages/jupyter_core/application.py”, line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File “/opt/conda/lib/python3.7/site-packages/traitlets/config/application.py”, line 658, in launch_instance
app.start()
File “/opt/conda/lib/python3.7/site-packages/nbconvert/nbconvertapp.py”, line 337, in start
self.convert_notebooks()
File “/opt/conda/lib/python3.7/site-packages/nbconvert/nbconvertapp.py”, line 507, in convert_notebooks
self.convert_single_notebook(notebook_filename)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/nbconvertapp.py”, line 478, in convert_single_notebook
output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/nbconvertapp.py”, line 407, in export_single_notebook
output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/exporter.py”, line 178, in from_filename
return self.from_file(f, resources=resources, **kw)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/exporter.py”, line 196, in from_file
return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/notebook.py”, line 32, in from_notebook_node
nb_copy, resources = super(NotebookExporter, self).from_notebook_node(nb, resources, **kw)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/exporter.py”, line 138, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/exporter.py”, line 315, in _preprocess
nbc, resc = preprocessor(nbc, resc)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/preprocessors/base.py”, line 47, in call
return self.preprocess(nb, resources)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py”, line 352, in preprocess
with self.setup_preprocessor(nb, resources, km=km):
File “/opt/conda/lib/python3.7/contextlib.py”, line 112, in enter
return next(self.gen)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py”, line 297, in setup_preprocessor
self.km, self.kc = self.start_new_kernel(cwd=path)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py”, line 246, in start_new_kernel
km.start_kernel(extra_arguments=self.extra_arguments, **kwargs)
File “/opt/conda/lib/python3.7/site-packages/jupyter_client/manager.py”, line 246, in start_kernel
kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments)
File “/opt/conda/lib/python3.7/site-packages/jupyter_client/manager.py”, line 170, in format_kernel_cmd
cmd = self.kernel_spec.argv + extra_arguments
File “/opt/conda/lib/python3.7/site-packages/jupyter_client/manager.py”, line 82, in kernel_spec
self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)
File “/opt/conda/lib/python3.7/site-packages/jupyter_client/kernelspec.py”, line 236, in get_kernel_spec
raise NoSuchKernel(kernel_name)
jupyter_client.kernelspec.NoSuchKernel: No such kernel named python2

Jupyter exited with status code: 1

Hi @Edward_Szajner,

I’d be happy to provide some suggestions, however, our expertise lies in the Losant Platform, so we do additionally recommend checking out the Jupyter Blog, the Jupyter Live Chat, or posting on the Jupyter Discourse Forum for problems within the Jupyter Notebook and help writing Notebook Code.

I am seeing this message in your error log:

Output file histogram.png not found.
Output file result.ipynb not found.

Have you configured these outputs? In the writing guide, since a specific name is given (output_path = os.path.join(os.environ['OUTPUT_DIR'], 'histogram.png')) in the Notebook file, it must be configured in Losant with the same name.

Thanks!
Julia

@Edward_Szajner,

I would also recommend checking out this helpful forum post on Debugging Losant Notebooks. The debug.ipynb file can be found on Github.

Thanks!
Julia

Julia,

I am not following what you are referring to with regards to the “histogram.png” and “result.ipynb” not being found. Where are you seeing these messages? I think my problem is the “histogram.png” file is not being created, on the Losant side, due to the error I am encountering.

From the Jupyter side I am seeing all the files in the correct directories as specified in the Writing Guidelines. Locally I am using the following environment variables to store the Jupyter data

INPUT_DIR=/Users/v111405/src/losant/analytics/inputs/
OUTPUT_DIR=/Users/v111405/src/losant/analytics/outputs/

As you can see from this output all of the Jupyter files are in the correct place and appear to be working as expected

(base) TUSFL04CML1100H:analytics v111405$ ls
inputs outputs testNotebook.ipynb
(base) TUSFL04CML1100H:analytics v111405$ pwd
/Users/v111405/src/losant/analytics
(base) TUSFL04CML1100H:analytics v111405$ ls inputs/
waterPump.csv
(base) TUSFL04CML1100H:analytics v111405$ ls outputs/
histogram.png
(base) TUSFL04CML1100H:analytics v111405$

I believe the issue is after I upload the “testNotebook.ipynb” file to the Losant Notebook and execute. From the execution log that I sent it things appear to be working as expected as the Notebook is started and it appears to be able to find the “waterPump.csv” data file as described in the “Input” tab of the Notebook (Image Included).

The main problem is for some reason the Output file is not being created (Image Included). I have also included the contents of the log file. I am not able to decipher the contents of the log file but the last line has an error which does not seem good. Not sure who is generating this. As I said it appears to be on the Losant side. Please advise

upyter_client.kernelspec.NoSuchKernel: No such kernel named python2

(Attachment result.log is missing)

Julia,

The “logfile” got rejected due to a bad file format. Here is the contents. As you can see there is an error on the last line which does not appear to be good. I can’t decipher the whole thing but it appears to be on the Losant side of the house and not Jupyter. Please advise

(base) TUSFL04CML1100H:Downloads v111405$ cat result.log
[NbConvertApp] Converting notebook /tmp/input.ipynb to notebook
Traceback (most recent call last):
File “/opt/conda/bin/jupyter-nbconvert”, line 10, in
sys.exit(main())
File “/opt/conda/lib/python3.7/site-packages/jupyter_core/application.py”, line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File “/opt/conda/lib/python3.7/site-packages/traitlets/config/application.py”, line 658, in launch_instance
app.start()
File “/opt/conda/lib/python3.7/site-packages/nbconvert/nbconvertapp.py”, line 337, in start
self.convert_notebooks()
File “/opt/conda/lib/python3.7/site-packages/nbconvert/nbconvertapp.py”, line 507, in convert_notebooks
self.convert_single_notebook(notebook_filename)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/nbconvertapp.py”, line 478, in convert_single_notebook
output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/nbconvertapp.py”, line 407, in export_single_notebook
output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/exporter.py”, line 178, in from_filename
return self.from_file(f, resources=resources, **kw)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/exporter.py”, line 196, in from_file
return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/notebook.py”, line 32, in from_notebook_node
nb_copy, resources = super(NotebookExporter, self).from_notebook_node(nb, resources, **kw)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/exporter.py”, line 138, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/exporters/exporter.py”, line 315, in _preprocess
nbc, resc = preprocessor(nbc, resc)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/preprocessors/base.py”, line 47, in call
return self.preprocess(nb, resources)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py”, line 352, in preprocess
with self.setup_preprocessor(nb, resources, km=km):
File “/opt/conda/lib/python3.7/contextlib.py”, line 112, in enter
return next(self.gen)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py”, line 297, in setup_preprocessor
self.km, self.kc = self.start_new_kernel(cwd=path)
File “/opt/conda/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py”, line 246, in start_new_kernel
km.start_kernel(extra_arguments=self.extra_arguments, **kwargs)
File “/opt/conda/lib/python3.7/site-packages/jupyter_client/manager.py”, line 246, in start_kernel
kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments)
File “/opt/conda/lib/python3.7/site-packages/jupyter_client/manager.py”, line 170, in format_kernel_cmd
cmd = self.kernel_spec.argv + extra_arguments
File “/opt/conda/lib/python3.7/site-packages/jupyter_client/manager.py”, line 82, in kernel_spec
self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)
File “/opt/conda/lib/python3.7/site-packages/jupyter_client/kernelspec.py”, line 236, in get_kernel_spec
raise NoSuchKernel(kernel_name)
jupyter_client.kernelspec.NoSuchKernel: No such kernel named python2

Jupyter exited with status code: 1

Hi @Edward_Szajner,

Our Education Lead, who wrote the writing guide and the writing-guide notebook, pointed out that we use Python 3 in the cloud. I am curious, are you using the Python 2 kernel locally?

Thanks,
Julia

Julia,

I have downloaded the Anaconda distro as recommended in the Juypter documentation in the Notebook writing guidelines. When I create a new Notebook via the Jupyter GUI “Python 2” is my only option. According to my version of Pytyon

(base) TUSFL04CML1100H:Downloads v111405$ python --version
Python 2.7.16 :: Anaconda, Inc.
(base) TUSFL04CML1100H:Downloads v111405$

You can see that it is Python 2.7.16 (Anaconda, Inc)

ed

Hi @Edward_Szajner,

First off, thank you so much for providing us all the information to help you debug. It’s been very helpful.

Looking into things, I think that’s the issue. You can see all the details of our environment here:

My recommendation would be to use the Python 3 Kernal. Here are some instructions I found:

https://ipython.readthedocs.io/en/latest/install/kernel_install.html#kernels-for-python-2-and-3

Overall, I would build your notebook using Python 3, eventually, Python 2 is being sunset.

1 Like

I updated my Jupyter environment to use Python 3 and recreated the Notebook based on the “Writing Guide”. It worked as expected. Thanks for the assistance on this. I was taken back by the amount of time it took to complete the Notebook run after getting the Input File Completed message. It took approximately 3 minutes. Seems like an extreme amount of time for such a simple calculation.