2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

必要最小限のjupyter_lab_config.pyを作る

Posted at

 JupyterLabで、初期ディレクトリと起動ブラウザを指定するだけのjupyter_lab_config.pyを作るPythonコードです。

import os


def generate_config():
    user = os.environ.get("USER")  # Ubuntuの環境変数
    username = os.environ.get("USERNAME ")  # Windowsの環境変数
    if user:  # Ubuntu
        config_list = [
            "c = get_config()",
            f"c.ServerApp.notebook_dir = '/home/{user}/Documents/'",
            "c.ServerApp.browser = '/usr/bin/google-chrome-stable --args --app=%s --start-maximized'",
        ]

        config_file = f"/home/{user}/.jupyter/jupyter_lab_config.py"

    elif username:  # Windows
        config_list = [
            "c = get_config()",
            f"c.ServerApp.notebook_dir = 'C:/Users/{username}/Documents'",
            "c.ServerApp.browser = '\"C:/Program Files/Google/Chrome/Application/Chrome.exe\" --app=%s --start-maximized'",
        ]

        config_file = f"C:/Users/{username}/.jupyter/jupyter_lab_config.py"

    else:
        return

    with open(config_file, "w") as f:
        f.write("\n".join(config_list))

    with open(config_file, "r") as f:
        print(f.read())

    return


generate_config()
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?