I have nbconvert version 6.4.2 installed on my macpro. And i am using following command to get html output from command line;
jupyter nbconvert --to html Used-air-loose-data.ipynb
But it gives a warning message;
File "/Users/jsingh/.local/share/virtualenvs/Air_assignee_analysis-SSL-Cc05/lib/python3.9/site-packages/jinja2/loaders.py", line 566, in load
raise TemplateNotFound(name)
jinja2.exceptions.TemplateNotFound: index.html.j2
But I can find some default templates at the location;
/Users/jsingh/.local/share/virtualenvs/Air_assignee_analysis-SSL-Cc05/share/jupyter/nbconvert/templates/lab
May I get some help here, how can I make the right template and put it in correct location. Thanks in advance.
Related
I am trying out Quarto, I am using R version 4.2.1. When I go to RStudio, File -> New File -> Quarto Document and create a new document, when I try to render via the RStudio Render button, I get the error 'C:/Program' is not recognized as an internal or external command, operable progam or batch file
I have tried installing R in a directory which has no white space in the installation path, but this did not resolve the issue.
UPDATE: on doing quarto check as suggested in comment gave me
Not sure what that means, but I was able to solve the problem by ensuring my qmd quarto file did not have white space in its name (replaced white space with underscores. The error then went away.
On changing my qmd file name, from HVL campaign.qmd to HVL_campaign.qmd (removing the white space), the rendering works. The error message was misleading though, that may need to get looked at...?
This error pops up if there is a space anywhere in the filepath unfortunately. I am running into this error when I try to make a new project in a directory that has a filepath with a space (thanks onderive...)
I'm attempting to convert a Jupyter Notebook to a pdf, but it throws this error at me:
nbconvert.exporters.pdf.LatexFailed: PDF creating failed, captured latex output:
Failed to run "xelatex notebook.tex -quiet" command:
notebook.tex:411: Missing $ inserted
notebook.tex:411: Extra }, or forgotten
notebook.tex:412: Missing $ inserted
It works if I take this LaTex out of my notebook:
$ y=\frac{1}{2}x+3 $
I'm not familiar with LaTex that much, but it displays correctly in the .ipynb file, so I'm assuming there is nothing wrong with this syntax. Is this an issue with nbconvert? Thank you!
After playing around a bit, I have solved the problem. It is an issue with LaTeX syntax. I wish jupyter notebooks make it to where the cell would show an error, but it doesn't. The correct syntax is the same as above except no spaces between the dollar signs. After changing that line of code to:
$y=\frac{1}{2}x+3$
nbconvert successfully made the PDF.
I want to hide certain parts of a jupyter notebook and came across tags which can achieve this. I've tagged the cells with remove_cell in my notebook an tried to run
$ jupyter nbconvert test.ipynb --TagRemovePreprocessor.remove_input_tags="{'remove_cell'}"
however I always get the following error:
traitlets.traitlets.TraitError: The 'remove_input_tags' trait of a TagRemovePreprocessor instance must be a set, but a value of type 'unicode' (i.e. u'{remove_cell}') was specified.
I've tried to change the "{'remove_cell'}" to various format, e.g. {'remove_cell'} etc with the same result. Any help would be appreciated
According to nbconvert documentation it must be done as you have specified. But there seems to be some bug in command line parsing traitlets API, used internally by jupyter nbconvert. So i tried a slightly different approach of specifying Configuration in jupyter_nbconvert_config.py file.
Steps:
jupyter nbconvert --generate-config
This will generate default ~/.jupyter/jupyter_nbconvert_config.py.
Edit the configuration file and specify your configuration, in this case
c.TagRemovePreprocessor.remove_input_tags = set(['remove_cell'])
Run jupyter nbconvert test.ipynb This will remove the tagged cells and convert it to default HTML page.
I got this to work without editing the config file by using square brackets, which match the format of the tag in the cell metadata, instead of curly braces.
So, in my cell metadata I have this:
{
"tags": ["remove_cell"]
}
and on the command line I used:
jupyter nbconvert test.ipynb --TagRemovePreprocessor.remove_input_tags="['remove_cell']"
which successfully removed any cells with this tag from the HTML output.
nbconvert did not hide the cells with tags while also executing the notebook, and this is the most useful example I found here https://github.com/jupyter/nbconvert/issues/1300:
So the underlying issue is that the preprocessors being added on your behalf are un-ordered, so by unlikely chance the --execute turning on the ExecutePreprocessor is getting applied after the TagRemovePreprocessor. To fix this you can set the preprocessors to use in an explicit order by doing:
jupyter nbconvert notebooks/demo_notebook.ipynb \
--TagRemovePreprocessor.remove_input_tags='{"remove-input"}' \
--TagRemovePreprocessor.remove_all_outputs_tags='{"remove-output"}' \
--Exporter.preprocessors='["nbconvert.preprocessors.ExecutePreprocessor","nbconvert.preprocessors.TagRemovePreprocessor"]' \
--to notebook
This has been an ongoing issue for me, as I would love to use Jupyter Notebook to write my research reports, but have found it very difficult to export my Jupyter Notebooks to PDF without code and without large formatting errors.
I am able to download the notebooks as PDF, but have not found a way to hide the code, or have the PDF resemble the formatting of the notebook.
No solution I've found on SO has been sufficient for my issue, so it may be possible that this is not the intended functionality of Jupyter Notebook.
Have you tried this:
jupyter nbconvert path/to/your/ipynb --to=pdf --TemplateExporter.exclude_input=True
For more on the flags, you can refer to nbconvert config options
I have successfully converted .ipynb to .html exclude the code blocks
I followed the suggestion by 0xffff above but the PDF output did not behave as intended (code blocks were still included).
However, their suggestion inspired me to try converting to html first using the following call:
jupyter nbconvert path/to/your/ipynb --to=html --TemplateExporter.exclude_input=True
This behaved as intended, and from there, it was straightforward to print the output to PDF in a browser.
Regarding the issue with the --to=pdf flag, I've opened up an issue on the Jupyter Notebook git repo: https://github.com/jupyter/notebook/issues/3804. Will report back once I get a response.
nbconvert
nbconvert is an official package, and other answers have mentioned it. However, they did not mention there are two ways to convert to PDF.
The default option uses LaTeX, and it's often a pain to install:
jupyter nbconvert notebook.ipynb --to=pdf
A newer option is to use the webpdf converter, this does not require LaTeX
jupyter nbconvert notebook.ipynb --to=webpdf
Quarto
Quarto is the newest option. The defaults are prettier than nbconvert, and it has advanced features to customize the output PDF. However, it uses pandoc (and pandoc uses LaTeX), so you must install both first.
quarto render notebook.ipynb --to pdf
Quarto is a new project, and I often run into problems (I couldn't convert the sample notebook); however, the project is in active development and I'm sure it will get better.
Online converters
The last option is to use one of the many online services. The two main caveats are 1) You might not want to upload your notebooks to some random website, and 2) It's often unclear what engine they use to convert the notebooks. I've tried many of them with mostly negative results.
I created one online converter that uses nbconvert and deletes your notebook as soon as it's converted.
If you manually create the PDF, there is a simpler solution: add the following code block & execute it
from IPython.core.display import HTML
HTML('<style>.input, .jp-InputArea {display: none !important}</style>')
Code will disappear both in the "normal" UI and in print preview / export to HTML. Open print preview, generate the PDF - it looks great now, clear the output of this one cell to bring the code back, done
I keep getting an error message when attempting to compile a pdf that reads:
It seems you are using the Sweave-specific syntax in line(s) 85; you may
need Sweave2knitr("Filename.Rnw") to convert it to knitr. Running
pdflatex.exe on File_Name_Update_FINAL.tex ...Running pdflatex.exe on
File_Name_Update_FINAL.tex ...failed
I have checked my settings in tools>global options>sweave and they are set to
Weave rnw files using: knitr
And checked box in always enable Rnw concordance.
I have also unchecked and checked the enable concordance box.
I have attached the code below. It starts on line 85, the line of code with the error.
\begin{document}
\SweaveOpts{concordance=TRUE}
%\SweaveOpts{concordance=TRUE}
Any help would be great. Thanks!