1. 安裝jupytext文件,
python3 -m pip install jupytext --user;
2. 生成修改jupyter notebook配置文件
jupyter notebook --generate-config -y echo 'c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"' >> ~/.jupyter/jupyter_notebook_config.py
3. 將jupytext添加到對應路徑中,export PATH=$PATH:/Users/XXXX/Library/Python/3.7/bin;
4. jupytext --to py abc.ipynb 生成對應的abc.py文件;
5. 將"jupytext": {"formats": "ipynb,py"}添加到jupyter notebook--jupyter界面--打開對應的abc.ipynb-編輯--編輯界面原數據的文件中。注意不要修改其它的配置;
這樣.py與.ipynb文件就可以同步了。只要git管理.py文件即可。
參考文獻:https://nextjournal.com/schmudde/how-to-version-control-jupyter