It's painful to let someone else edit ~ / .jupyter / jupyter_notebook_config.py
with jupytext's automatic conversion settings. I have a good setting method so I will share it.
Place the file with the following contents in the root of the project.
jupytext.yml
default_jupytext_formats: "ipynb,py:percent"
jupytext is a tool to convert .ipynb
files to .py
, .R
, .jl
, .md
, .Rmd
and so on. By setting it, it works with jupyter lab and automatically converts it when saving a file. It can also be executed from the command line, so it is versatile.
There is another tool for converting to .ipynb-> .py
, nbconvert
, but it requires a lot of ingenuity to convert automatically when saving.
Analyzing with multiple people will reveal the bad points of .ipynb
.
There are some
--It's heavy to manage git.
--It is in json
format and difficult to read at the time of review.
It is difficult to share.
One solution to this is to convert it to python format. This makes the notebook lightweight and easy to read, which is a nice touch.
You can also reproduce the notebook without any problem by converting .py
-> .ipynb
.
#Pipenv environment
python 3.8.5
jupyterlab 2.2.6
If you are not using pipenv, replace it with a good one.
$ pipenv install jupytext
When you start jupyter lab after installation, you will be asked if you want to build, so please build as it is.
If you want to build manually, use pipenv run jupyter lab build
.
There are four setting methods.
.ipynb
metadatajupytext --set-formats ipynb,py notebook.ipynb
~ / .jupyter / jupyter_notebook_config.py
1 and 2 need to be set for each file, which is troublesome. Operation cannot be guaranteed for 3 because it is necessary to operate files outside the repository.
This time, I will explain about No. 4. This way it's kind because it's already set up when someone pulls the repository.
Create a configuration file with one of the following names.
.jupytext
jupytext.toml
jupytext.yml
jupytext.yaml
jupytext.json
jupytext.py
Or the format with .
added to the beginning of these
If you put this file in the root of the project, it will be read automatically. Please check the reference link for details on the location.
Automatic conversion will be effective by writing as follows. This time I wrote it in yaml.
jupytext.yml
default_jupytext_formats: "ipynb,py:percent"
Considering the use with VS Code and PyCharm, the py: percent
format is recommended for python files.
As a result, I think the directory structure will look like this.
.
├── Pipfile
├── Pipfile.lock
├── notebook.ipynb #Created notebook
├── notebook.py #Converted and generated python
└── jupytext.yml #setting file
-- .ipynb <-> .py
conversion makes it easier for teams to manage code.
--Jupytext can be automatically converted when saving a file.
--There are various ways to set Jupytext
--Easy to share settings with configuration file
--py: percent
is safe
that's all!
Configuration — Jupytext documentation
Recommended Posts