You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Datalab中所有Notebook配置类似Jupyter的启动脚本?

Does Google Cloud Datalab have an equivalent to Jupyter's startup script folder?

Great question! Yes, Datalab does offer a similar functionality to Jupyter's ~/.ipython/profile_default/startup folder for running Python code automatically when a Notebook kernel starts—and it's distinct from the /content/datalab/.config/startup.sh script you mentioned. Here's how it works:

How to set up auto-run Python scripts for Notebook kernels

  • Global scope (all Notebooks)
    Place your .py startup scripts in the /usr/local/share/datalab/startup/ directory. Any Python files here will execute automatically every time a new Notebook kernel initializes. This is perfect for common tasks like importing frequently used modules (from mymodels import *) or configuring database connections (my_db.configure(production.ini)).

  • Project-specific scope
    If you only want scripts to run for Notebooks in a specific project, create a datalab/startup/ subfolder within your project's root directory. Drop your startup .py files here, and only Notebooks in that project will load them on kernel startup.

Key difference from /content/datalab/.config/startup.sh

As you noted, startup.sh runs before the Notebook daemon starts—it's meant for system-level tasks like installing dependencies, setting environment variables, or modifying system configurations. The Python startup scripts we discussed run when the kernel starts, just like Jupyter's startup folder, focusing specifically on Python runtime setup.

Quick way to test

Create a simple test script, e.g., /usr/local/share/datalab/startup/test_init.py, with:

print("Datalab startup script executed!")
my_global_var = "Available in all notebooks"

When you launch a new Notebook, you'll see the print message in the kernel logs, and my_global_var will be immediately available in your Notebook cells without manual import.

内容的提问来源于stack exchange,提问作者Charles V.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:38:31