[PYTHON] Convert .ipynb to .html (with BatchFile)

Conclusion

--Put a batch file and click! Then I made something that converts the .ipynb directly under it to html. --It works even in an environment without python (should) --toc2 (table of contents function) is automatically inserted ← Recommended point of this function! </ Strong> --I made it on mac, but it may work on windows if I rebuild it. (unconfirmed)

demo

background

――It's hard to start a local server and open a notebook every time to check the contents of a large amount of .ipynb sent. Furthermore, if you are working in a different directory for other work, you will have to set up a number of local servers, which will not be the place for work.

Existing method

--Method 1: Convert @yorshka .ipynb to .html

jupyter nbconvert --to html hoge.ipynb

--Method 2: Official: Customizing nbconvert --HTML conversion using template ("simplepython.tpl" in the example below). With this method, the table of contents in nbextension such as toc2 can be included as html.

jupyter nbconvert --to python 'example.ipynb' --stdout --template=simplepython.tpl

--Method 3: Open and save noebook on LocalServer スクリーンショット 2020-02-11 12.53.25.png

Problems / issues that cannot be solved

――It's painful when you have to see a lot of .ipynb --Forget the path in template.tpl --Movement of directory is troublesome --You have to put various packages (jupyter, nbconvert, nbextensions, toc2.tpl etc ...) in the python environment. (I want the environment to be simple!) -↑ I can't remember the existence of the package because I created a virtual environment and replaced it from time to time.

approach

Implement GUI-based processing. (Combines existing method commands into one executable file.)

--The package used --pyinstaller: 1 Create an executable file --Jupyter: Use functions such as nbconvert to convert to text-> notebook format-> html --jinja2: Used when loading some template.tpl --Various templates loaded by jinja2 when launching jupyter notebook such as toc2.tpl, full.tpl ...:

――If you feel like the specific contents, I will add it - git link

Effect / conclusion

――It's working properly so far, and it's convenient to be converted to html in 5 seconds.

  • The remaining challenges --The file size is large (about 50MB) and it puts pressure on the hdd. --Processing time is long. If possible, I want you to finish html conversion in about 0.5 seconds.

Bonus (where I got stuck)

--I had a hard time embedding the templates in the batchfile.
Because pyinstaller did not recognize the following template file. It's an essential file for jinja2 to convert from text to html.

  • toc2.tpl
  • full.tpl
  • nbextensions.tpl
  • mathjax.tpl
  • celltags.tpl

--As a solution to ↑, I hard-coded .tpl and created a file to read as a string. (Data_tpl.py) It seems that pyinstaller recognizes .pyfile without permission. ――After that, if you convert the template read by string with jinja2.dictLoader, you can inherit jinja2 ({%-extends'hogehoge.html'%}) without permission.

Recommended Posts

Convert .ipynb to .html (with BatchFile)
Convert 202003 to 2020-03 with pandas
Convert HTML to text file
Common html to rent with Django
convert ggplot based graph to html
Convert list to DataFrame with python
Convert sentences to vectors with gensim
Convert PDF to image with ImageMagick
Download Google logo → Convert to text with OCR → Display on HTML
Convert memo at once with Python 2to3
HTML email with image to send with python
Convert from PDF to CSV with pdfplumber
Convert character strings to features with RoBERTa
Convert Excel data to JSON with python
Convert Hiragana to Romaji with Python (Beta)
Convert FX 1-minute data to 5-minute data with Python
Convert PDF files to PNG files with GIMP
Convert array (struct) to json with golang
Convert HEIC files to PNG files with Python
Convert Chinese numerals to Arabic numerals with Python
Convert from Markdown to HTML in Python
Sample to convert image to Wavelet with Python
Convert to HSV
I made a tool to convert Jupyter py to ipynb with VS Code
Convert DICOM to PNG with Ascending and Descending
Convert data with shape (number of data, 1) to (number of data,) with numpy.
Convert PDF to image (JPEG / PNG) with Python
Convert PDFs to images in bulk with Python
Convert mp4 to mp3 with ffmpeg (thumbnail embedded version)
Convert svg file to png / ico with Python
Convert Windows epoch values to date with python
Easily convert Jupyter Notebooks to blogs with fastpages
How to convert (32,32,3) to 4D tensor (1,32,32,1) with ndarray type
Convert strings to character-by-character list format with python
Convert jupyter notebook .ipynb files to python executable .py files
I want to convert an image to WebP with lollipop
How to convert / restore a string with [] in python
0 Convert unfilled date to datetime type with regular expression
Convert kanji to kana
Convert a text file with hexadecimal values to a binary file
How to convert horizontally held data to vertically held data with pandas
How to convert a class object to a dictionary with SQLAlchemy
Convert jupyter to py
Convert keras-yolo3 to onnx
Convert the image in .zip to PDF with Python
How to convert JSON file to CSV file with Python Pandas
Convert dict to array
PyInstaller memorandum Convert Python [.py] to [.exe] with 2 lines
Convert json to excel
Convert numeric variables to categorical with thresholds in pandas
Convert Select query obtained from Postgre with Go to JSON
How to convert an array to a dictionary with Python [Application]
Convert color space from RGB to CIELAB with PIL (Pillow)
Double-click ipynb in windows + anaconda environment to open with jupyter-notebook
Convert images to sepia toning with PIL (Python Imaging Library)
Convert garbled scanned images to PDF with Pillow and PyPDF
Convert video to black and white with ffmpeg + python + opencv
Try to factorial with recursion
Connect to BigQuery with Python
Convert hexadecimal string to binary
[python] Convert date to string