Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert the Ipython kernel on kaggle to pdf and download it?

I want to download all the simulation with code and respective output in a .pdf file. Is there any way that it can be possible?

I'have tried downloading the Ipython notebook and opening it on my PC in jupyter notebook and then converting it to pdf. But I'm searching for the direct way to do it.

like image 396
Gopal Kalpande Avatar asked Jan 30 '19 19:01

Gopal Kalpande


People also ask

How do I download a kaggle file as a PDF?

Right click the page to print to PDF or save to HTML.

How do I save an IPython notebook as a PDF?

The Jupyter Notebook has an option to export the notebook to many formats. It can be accessed by clicking File -> Download as -> PDF via LaTeX (or PDF via HTML - not visible in the screenshot).


1 Answers

TL;DR

As of now, downloading the jupyter notebook and then converting it to PDF is the quickest way.


If you still wish to convert the notebook to PDF on kaggle itself, you can do it using command line by following these steps:

Note that the Internet should be connected (check from the right menu).

1. Ensure all necessary libraries are installed.

!pip install nbconvert  # already-installed (most probably)
!apt install pandoc  # already-installed
!apt install texlive-xetex -y  # this'll take a long time

2. Use nbconvert to convert jupyter notebook to PDF

!ls  # will output notebook name e.g. `__notebook_source__.ipynb`

!jupyter nbconvert --execute --to pdf __notebook_source__.ipynb

3. Now, either you can Commit and Run (see Edit below) and get this file on Output tab or simply upload it using SSH or third-party service like transfer.sh (Use file.io, transfer.sh doesn't work anymore).

#!curl --upload-file __notebook_source__.pdf https://transfer.sh/notebook.pdf
!curl -F "file=@__notebook_source__.pdf" https://file.io

This will output a url like this:
https://file.io/uYWP0azE2soj Go to the url and get your file.


Note that you can skip installing texlive-xetex if you only want HTML file.


Edit: It turns out Kaggle has changed it GUI a little bit, so, if you're Commiting and Running by clicking on Save Version and you're doing a Quick Save, then you need to select Save output for this version in Advanced Settings in order to save output pdf file. Or you can simply use Save & Run All (Commit), it'll save output pdf as well.

like image 123
kHarshit Avatar answered Oct 07 '22 04:10

kHarshit