mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-16 22:42:57 +00:00
Use custom conda environment in Jupyter Notebook when user wants to use it (#2050)
* Modify the custom Python kernel - to activate the custom environment - for the respective Jupyter Notebook and Jupyter Console Signed-off-by: Ayaz Salikhov <mathbunnyru@gmail.com> * Add DL3059 to hadolint ignore list Signed-off-by: Ayaz Salikhov <mathbunnyru@gmail.com> * Move hadolint ignore to a single line * Use python heredoc * Remove unused print * Fix style * Do not hardcode CONDA_DIR * Update custom_environment.dockerfile * Use indent=1 * Implement activate_notebook_custom_env.py as a separate script * Do not call Python manually --------- Signed-off-by: Ayaz Salikhov <mathbunnyru@gmail.com> Co-authored-by: Olivier Benz <olivier.benz@b-data.ch>
This commit is contained in:
24
images/minimal-notebook/setup-scripts/activate_notebook_custom_env.py
Executable file
24
images/minimal-notebook/setup-scripts/activate_notebook_custom_env.py
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
env_name = sys.argv[1]
|
||||
CONDA_DIR = os.environ["CONDA_DIR"]
|
||||
|
||||
file = Path.home() / f".local/share/jupyter/kernels/{env_name}/kernel.json"
|
||||
content = json.loads(file.read_text())
|
||||
content["env"] = {
|
||||
"XML_CATALOG_FILES": "",
|
||||
"PATH": f"{CONDA_DIR}/envs/{env_name}/bin:$PATH",
|
||||
"CONDA_PREFIX": f"{CONDA_DIR}/envs/{env_name}",
|
||||
"CONDA_PROMPT_MODIFIER": f"({env_name}) ",
|
||||
"CONDA_SHLVL": "2",
|
||||
"CONDA_DEFAULT_ENV": env_name,
|
||||
"CONDA_PREFIX_1": CONDA_DIR,
|
||||
}
|
||||
|
||||
file.write_text(json.dumps(content, indent=1))
|
Reference in New Issue
Block a user