[PYTHON] Complete everything with Jupyter ~ Introduction of nbdev ~

This article is the 4th day post of Bakan Advent Calendar 2019. This is an article for Jupyterer. Please check the formula for details, as some parts are not well understood.

What is nbdev

Perhaps briefly, it's a Python programming environment that completes the task with a single Jupyter Notebook by including the IDE role. Created by fast.ai and currently under development [fastai v2](https://forums.fast.ai/t/fastai-v2-read- This-before-posting-please / 53517) also uses nbdev.

Currently, trial and error such as EDA and model construction is often done using Jupyter Notebook, and it exists as the role of "exploring". However, it is common to use the IDE in the subsequent phases.

nbdev is trying to complete it on jupyter by providing the following functions. ・ Creating a py file ・ Creating a README ・ Visual diff ・ Confirmation and correction of merge conflict

(Borrowed from the official below) image.png

Tutorial / How to use

The following is done on Mac, but the procedure is the same on Win.

Installation ~ Until Jupyter opens

1- Install from the terminal with the following command. pip install nbdev

2- Official creates template, so create Repository based on it. image.png

3- Clone the created Repository. git clone [URL below]

image.png

4-Edit settings.ini to add information about the repository to be linked. Uncomment the following items in settings.ini and edit as shown in the entry example.


Before editing
image.png


Entry example
image.png

lib_name, user, description correspond to the created repository. I don't know what keywords refers to, but please enter an appropriate string.

5-Type the following command from the terminal to create the lib_name directory. nbdev_build_lib

image.png

(In the image above, Pipfile and Pipfile.lock are displayed, but they are irrelevant and should be ignored)

6-Open Jupyter Notebook with jupyter notebook.

Creating a py file

Open 00_core.ipynb and follow the steps below to create a module.

  1. For what you want to convert to a python module, add # export to the beginning of the cell.
  2. Type the following two rows into the cell and execute. (Or run nbdev_build_lib on the terminal.) from nbdev.export import * notebook2script()


The following example
image.png

As a result, what you specify with # export will be listed in core.py under the lib_name directory. The core.py is updated each time you perform step 2, so in addition to adding it, you can delete it by erasing the existing cell.

image.png

Editing the README

When you open 99_index.ipynb, the following template will be displayed. Since the cell with # hide is hidden, we will import the module including the one with # export here.


Template
image.png


The following example
image.png

After editing is complete, run nbdev_build_docs on the terminal to update the README.md in the directory.

After that, when you push to the remote repository, the README on github will show the following.

image.png

in conclusion

[How was it? ](Https://www.google.com/search?ei=BGXmXczDEIj90gTEkJ-IDg&q=%E3%81%84%E3%81%8B%E3%81%8C%E3%81%A7%E3%81%97 % E3% 81% 9F% E3% 81% 8B & oq =% E3% 81% 84% E3% 81% 8B% E3% 81% 8C% E3% 81% A7% E3% 81% 97% E3% 81% 9F% E3% 81% 8B & gs_l = psy-ab.3..0l9j0i7i30.0.0..1423 ... 0.0..0.158.225.1j1 ...... 0 ...... gws-wiz.dTg3WBRsT_o & ved = 0ahUKEwjM1ZHXzJnmAhWIvpQKHUTIB- EQ4dUDCAs & uact = 5) I introduced the outline of nbdev and a part of how to use it. We hope that this article will give you an opportunity to try out nbdev. Please check the following references as some parts may not be covered.

References

Nbdev: use Jupyter Notebooks for everythingWelcome to nbdevNbdev discussionA Step-by-Step Introduction to Starting nbdev — Exploratory ProgrammingIntroduction to git that will not be frustrated this time, Part 1

Reference link

Vacan, Inc.Vacan Advent Calendar 2019

Reference information

Our CEO is Kaggle's recommendation.

Recommended Posts

Complete everything with Jupyter ~ Introduction of nbdev ~
Easy introduction of speech recognition with Python
[EDA] Introduction of Sweetviz (comparison with + pandas-profiling)
Introduction of PyGMT
Fill the browser with the width of Jupyter Notebook
Introduction of cymel
Introduction of Python
Play with the UI implementation of Pythonista3 [Super Super Introduction]
[Chapter 5] Introduction to Python with 100 knocks of language processing
[Chapter 6] Introduction to scikit-learn with 100 knocks of language processing
[Chapter 3] Introduction to Python with 100 knocks of language processing
[Chapter 4] Introduction to Python with 100 knocks of language processing
Multiple selections with Jupyter
Candlestick with plotly + Jupyter
Introduction of trac (Windows + trac 1.0.10)
Introduction of Virtualenv wrapper
Simulation of complete gacha
Use nim with Jupyter
I wrote the basic grammar of Python with Jupyter Lab
[Raspi4; Introduction to Sound] Stable recording of sound input with python ♪
I wrote the basic operation of matplotlib with Jupyter Lab