TemplateNotfound error while converting notebook into pdf - jupyter

I have a .ipynb file in my virtual environment. I have following packages installed ;
nbconvert 6.4.0
pandoc 2.17.0.1
texshop 4.62
Inside my virtual environment I run this command;
jupyter nbconvert --to pdf transit_time_notebook.ipynb
But it is failing with this error message;
File "/Users/jsingh/.local/share/virtualenvs/operational_quality-CNT8izRC/lib/python3.8/site-packages/jinja2/loaders.py", line 566, in load
raise TemplateNotFound(name)
jinja2.exceptions.TemplateNotFound: index.tex.j2
Can I please get some help to how to fix this issue?I feel I have all required libraries needed for nbconvert to work.
Help is appreciated.

From what I'm reading in nbconvert documentation, it seems that the command you need is jupyter nbconvert transit_time_notebook.ipynb --to pdf transit_time_notebook.pdf.
https://nbconvert.readthedocs.io/en/latest/usage.html

Related

Open ipynb on Visual Studio Code, display json

When I open an ipynb file, I just see a json file. I tested with all files of :
https://github.com/MicrosoftLearning/mslearn-ai900.git
I have on my machine :
Python 3.9.6 installed
Installed with pip command : jupyterlab, notebook and voila
On Visual Studio Code (version 1.59.0) :
Python 3.9.6 64-bit is the current interpreter.
I can create a new notebook : "CTRL+SHIFT+P --> Jupyter : Create new blank notebook"
and I saw on the down-right "Jupyter Server:local". I can execute code : print("Hello, Python!"), but when I try to save file, I have this error :
Failed to register 'Untitled-1' : File name file:///*ThePathToSave*/Test.ipynb is not supported by Jupyter.
Extensions installed :
Jupyter v2021.8.1195043623
Pylance v2021.8.1
Python v2021.8.1105858891
List of kernel : (command) jupyter kernelspec list
Available kernels:
.net-csharp C:\Users\antho\AppData\Roaming\jupyter\kernels\.net-csharp
.net-fsharp C:\Users\antho\AppData\Roaming\jupyter\kernels\.net-fsharp
.net-powershell C:\Users\antho\AppData\Roaming\jupyter\kernels\.net-powershell
python3 c:\python\python39\share\jupyter\kernels\python3
Thanks for your help.
I re-install all Visual Studio Code.
I followed this answer to uninstall 'completely' VS Code :
https://debug.to/1074/how-to-uninstall-vs-code-completely
and after, I re-install Visual Studio Code.
Now I can open all files.
Thanks to #IanHuff

installing python package in sagemaker sparkmagic pyspark notebook

I want to install new libraries in a running kernel (not bootstrapping). I'm able to create a sagemaker notebook, which is connected to a EMR cluster, but installing package is a headache.
Unable to install packages on notebook. I've tried several methods like installing packages via terminal in jupyterLab.
$ conda install numba
The installation seems to be working fine on conda_pytorch_p36 notebook, but the packages are not installed on SparkMagic (pyspark) notebook.
Error code:
An error was encountered:
No module named numba
Traceback (most recent call last):
ImportError: No module named numba
The jupyter magic command also doesn't work only in pyspark notebook
!pip install keras
Error:
An error was encountered:
invalid syntax (<stdin>, line 1)
File "<stdin>", line 1
!pip install keras
^
SyntaxError: invalid syntax
Based on answer in a github post, neither did this work
from subprocess import call
call("pip install dm-sonnet".split(" "))
when you are running $ conda install numba via the terminal in JupyterLab,
it's actually succeeding the installation on your local environment. The thing is, when you are using Sparkmagic as your kernal, the code in the cells are always running on the spark cluster, not on the local notebook environment. To run the content of a cell locally you should write %%local in the beginning of the cell. After that everything in that cell will run locally and the installed module will be available.
Otherwise you should install the module on the remote spark cluster.
Read more here:
https://github.com/jupyter-incubator/sparkmagic/blob/master/examples/Pyspark%20Kernel.ipynb

Open WebP images in GCE Deep Learning VM

In python code, I need to process webp images. But when I try to open it with python PIL module, I have an error:
OSError: cannot identify image file 'my_image.webp
My Deep Learning image is created from GCP Marketplace VM (tensorflow image), but it seems that webp format is not "activated" at the pillow level.
Is the webp format supported in python by default?
What do I need to do/install/import on the VM to be able to open webp images with python PIL?
My python code steps:
>>>import PIL
​
>>>print(PIL.__version__)
6.0.0.post0
>>>from PIL import features
>>>print (features.check_module('webp'))
False
>>> PIL.Image.open('my_image.webp')
/usr/local/lib/python3.5/dist-packages/PIL/Image.py:2703: UserWarning: image file could not be identified because WEBP support not installed
warnings.warn(message)
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-4-99a62d35da67> in <module>
----> 1 PIL.Image.open('BATIMENT0000000045936174_flatRoof.webp')
/usr/local/lib/python3.5/dist-packages/PIL/Image.py in open(fp, mode)
2703 warnings.warn(message)
2704 raise IOError("cannot identify image file %r"
-> 2705 % (filename if filename else fp))
2706
2707 #
OSError: cannot identify image file 'my_image.webp'
Open JupyterLab UI of your GCP VM and run a Terminal session. In the terminal run these commands to install webp library:
pip uninstall Pillow
pip uninstall Pillow-SIMD
sudo apt install libwebp-dev
pip install Pillow-SIMD
Restart your Jupyter kernel. Now PIL is able te read webp images.
Ran into a similar issue on one of my servers.
Used the commands mentioned above, but was still getting False when running features.check_module('webp')
Turns out when reinstalling Pillow-SIMD, you need to make sure you're not using the cached version of the build, otherwise you won't get the WEBP support. So changing the last step to: pip install Pillow-SIMD --no-cache-dir solved it for me.
I would've added this as a comment but I don't have enough rep!

NBExtension does not validate in Jupyter Notebook

I am running Jupyter 4.1.0 on a Mac which I downloaded with Anaconda.
I have tried downloading front-end extensions to Jupyter Notebook but cannot get the packages to validate. For example after I downloaded calico-document-tools with:
jupyter nbextension install https://github.com/Calysto/notebook-extensions/archive/master.zip
When I try to validate it, I get the following.
$ jupyter nbextension enable calico-document-tools
Unrecognized JSON config file version, assuming version 1
Enabling notebook extension calico-document-tools...
- Validating: problems found:
- require? X calico-document-tools
What does this error message mean?

How do I install Scala in Jupyter IPython Notebook?

Here's a few links that I went to and did exactly what they said. I don't know what I'm doing wrong.
https://github.com/alexarchambault/jupyter-scala
https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages
https://github.com/apache/incubator-toree
http://jcrudy.github.io/blog/html/2013/12/08/introduction_to_iscala.html
None of this is working. It may be some way that my node is configured. I just don't know. Please help.
I tried the following with Jupyterhub notebook and it works seamlessly:
# Step 1: Install spylon kernel
pip install spylon-kernel
# Step 2: create a kernel spec
python -m spylon_kernel install
# Step 3: start jupyter notebook
jupyter notebook
PS: to list all installed kernels, you can run the following command:
jupyter kernelspec list
You can use the information given here.
Ensure you have IPython 3 installed. ipython --version should return a
value >= 3.0. If it's not the case, a quick way of setting it up
consists in installing the Anaconda Python distribution, and then
running
$ pip install --upgrade "ipython[all]"
ipython --version should then return a value >= 3.0.
Download the Jupyter Scala binaries for Scala 2.10 (txz or zip) or
Scala 2.11 (txz or zip), and unpack them in a safe place. Then run
once the jupyter-scala program (or jupyter-scala.bat on Windows) it
contains. That will set-up the Jupyter Scala kernel for the current
user.
Check that Jupyter/IPython knows about Jupyter Scala by running
$ jupyter kernelspec list
This should print, among others, a line like
scala211
(or scala210 dependending on the Scala version you chose).
Then run either IPython console with
$ ipython console --kernel scala211
and start using the Jupyter Scala kernel straightaway, or run Jupyter
Notebook with
$ jupyter notebook
and create Scala 2.11 notebooks by choosing Scala 2.11 in the dropdown
in the upper right of the Jupyter Notebook start page.
Note: Since IPython has now been replaced by Jupyter, we replaced ipython in the above commands with jupyter.
I've just run:
conda create --name base2 --clone base to create an env just like base.
conda activate base2 to move to the new env.
conda install -c conda-forge spylon-kernel.
python -m spylon_kernel install --user. create a kernel spec for Jupyter notebook
jupyter-notebook
...and works just fine.
I'm using:
Anaconda 4.7.12
Jupyter-notebook 6.0.1
Ubuntu 18.04
ipykernel 5.1.3
ipython 7.9.0
ipython_genutils 0.2.0
jupyter_client 5.3.4
jupyter_core 4.6.0
traitlets 4.3.3
from def suma(a: Int) = a + 3
I can't add a comment to Heapify's answer, but his solution worked for JupyterLab on Windows without problems.
I cut and pasted his code into an Anaconda Powershell prompt
pip install spylon-kernel
python -m spylon_kernel install
jupyter notebook
And refreshed my anacopnda launcher and the spylon project option was available.
The answer for Linux can be found here.
Install Scala. Add these lines to ~/.bashrc
export SCALA_HOME=/usr/local/share/scala export
PATH=$PATH:$SCALA_HOME/bin:$PATH
Follow these instructions from the
GitHub site:
Download and unpack pre-packaged binaries Scala 2.11. Unpack each
downloaded archive(s), and, from a console, go to the bin
sub-directory of the directory it contains. Then run the following to
set-up the corresponding Scala kernel:
./jove-scala --kernel-spec
Make sure spark is installed in local along with SPARK_HOME is added or exported in .profile/environment file.
If not, you might get stuck with the following message:
"Intitializing Scala interpreter ..."
without any result.
For mac, I needed only to 3 commands to add Scala and run it with Spark (I had it already installed) on my Jupyter notebook
pip install spylon-kernel
python -m spylon_kernel install
ipython notebook
Once you run them on your terminal, you'll have spylon-kernel in your notebook, which can be used as your a Scala notebook.
spylon-kernel hasn't seen an update in years. These days its much better to use almond.