Is there a way to easily include template cells that run shell commands in a notebook. I have some setup scripts for notebooks on Google Collab that install dependencies etc. They are common to many notebooks any currently if I need to update the cell I have to do it in every notebook. Is it possible to create some kind of reference?
As an example the code below checks a list of dependencies and installs them if not available:
try:
import importlib
for name, path in DEPENDENCIES:
importlib.import_module(name)
except (ImportError, ModuleNotFoundError):
if 'google.colab' in str(get_ipython()):
print('Running on CoLab')
from google.colab import drive
drive.mount('/content/drive')
!mkdir -p ~/.access
...
You can create a function in a regular python module and import that python module in all the jupyter notebooks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.