Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
j4j_notebooks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tim Kreuzer
j4j_notebooks
Commits
55cc79f0
Commit
55cc79f0
authored
5 years ago
by
Jens Henrik Göbbert
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
106db109
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Create_JupyterKernel.ipynb
+322
-0
322 additions, 0 deletions
Create_JupyterKernel.ipynb
PythonPackages.ipynb
+248
-240
248 additions, 240 deletions
PythonPackages.ipynb
with
570 additions
and
240 deletions
Create_JupyterKernel.ipynb
0 → 100644
+
322
−
0
View file @
55cc79f0
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# - Create your own Jupyter Kernel -"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"## Building your own Jupyter kernel is a three step process\n",
"1. Create/Pimp new virtual Python environment\n",
" * venv\n",
"2. Create/Edit launch script for the Jupyter kernel\n",
" * kernel.sh\n",
"3. Create/Edit Jupyter kernel configuration\n",
" * kernel.json"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Settings"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Set new kernel name\n",
" - change if you like"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"export KERNEL_NAME=${USER}_kernel\n",
"echo ${KERNEL_NAME}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Set directory for kernels virtual environment\n",
" - change if you like"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"export KERNEL_VENVS_DIR=${PROJECT}/${USER}/jupyter/kernels/\n",
"mkdir -p ${KERNEL_VENVS_DIR}\n",
"echo ${KERNEL_VENVS_DIR}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Set location of kernel spec\n",
" - select one:\n",
" - personal kernel = \"\\${HOME}/.local/\" \n",
" - project kernel = \"\\${PROJECT}/.local/\" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"export KERNEL_SPECS_DIR=${HOME}/.local/\n",
"#export KERNEL_SPECS_DIR=${PROJECT}/.local/\n",
"echo ${KERNEL_SPECS_DIR}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Create/Pimp new virual Python environment"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 1.1 - Load required modules"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"module -q purge\n",
"module -q use $OTHERSTAGES \n",
"module -q load Stages/Devel-2019a 2> /dev/null\n",
"module -q load GCCcore/.8.3.0 2> /dev/null\n",
"module -q load Jupyter"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 1.2 - Load extra modules you need for your kernel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# module load <module you need>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 1.3 - Create and activate a virtual environment for the kernel \n",
"and ensure python packages installed in the virtual environment are always prefered"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"python -m venv --system-site-packages ${KERNEL_VENVS_DIR}/${KERNEL_NAME}\n",
"source ${KERNEL_VENVS_DIR}/${KERNEL_NAME}/bin/activate\n",
"export PYTHONPATH=${VIRTUAL_ENV}/lib/python3.6/site-packages:${PYTHONPATH}\n",
"echo ${VIRTUAL_ENV}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 1.4 - Install Python libraries required for communication with Jupyter"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pip install --ignore-installed ipykernel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 1.5 - Install whatever else you need in your Python virtual environment (using pip)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#pip install <python-package you need>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Create/Edit launch script for the Jupyter kernel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 2.1 - Create launch script, which loads your Python virtual environment and starts the ipykernel process inside:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"echo '#!/bin/bash\n",
"\n",
"# Load required modules\n",
"module purge\n",
"module load $OTHERSTAGES'\"\n",
"module load Stages/Devel-2019a\n",
"module load GCCcore/.8.3.0\n",
"module load Jupyter\n",
"\n",
"# Load extra modules you need for your kernel (as you did in step 1.2)\n",
"#module load <module you need>\n",
" \n",
"# Activate your Python virtual environment\n",
"source ${KERNEL_VENVS_DIR}/${KERNEL_NAME}/bin/activate\n",
" \n",
"# Ensure python packages installed in the virtual environment are always prefered\n",
"export PYTHONPATH=${VIRTUAL_ENV}/lib/python3.6/site-packages:\"'${PYTHONPATH}'\"\n",
" \n",
"exec python -m ipykernel \"'$@' > ${VIRTUAL_ENV}/kernel.sh\n",
"chmod +x ${VIRTUAL_ENV}/kernel.sh"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Create/Edit Jupyter kernel configuration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 3.1 - Create Jupyter kernel configuration directory and files"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"python -m ipykernel install --name=${KERNEL_NAME} --prefix ${KERNEL_SPECS_DIR}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 3.2 - Adjust kernel.json file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mv ${KERNEL_SPECS_DIR}/share/jupyter/kernels/${KERNEL_NAME}/kernel.json ${KERNEL_SPECS_DIR}/share/jupyter/kernels/${KERNEL_NAME}/kernel.json.orig\n",
"\n",
"echo '\n",
"{\n",
" \"argv\": [\n",
" \"'${KERNEL_VENVS_DIR}/${KERNEL_NAME}/kernel.sh'\",\n",
" \"-m\",\n",
" \"ipykernel_launcher\",\n",
" \"-f\",\n",
" \"{connection_file}\"\n",
" ],\n",
" \"display_name\": \"'${KERNEL_NAME}'\",\n",
" \"language\": \"python\"\n",
"}' > ${KERNEL_SPECS_DIR}/share/jupyter/kernels/${KERNEL_NAME}/kernel.json"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Bash",
"language": "bash",
"name": "bash"
},
"language_info": {
"codemirror_mode": "shell",
"file_extension": ".sh",
"mimetype": "text/x-sh",
"name": "bash"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% Cell type:markdown id: tags:
# - Create your own Jupyter Kernel -
%% Cell type:markdown id: tags:
---
## Building your own Jupyter kernel is a three step process
1.
Create/Pimp new virtual Python environment
*
venv
2.
Create/Edit launch script for the Jupyter kernel
*
kernel.sh
3.
Create/Edit Jupyter kernel configuration
*
kernel.json
%% Cell type:markdown id: tags:
### Settings
%% Cell type:markdown id: tags:
*
Set new kernel name
-
change if you like
%% Cell type:code id: tags:
```
bash
export
KERNEL_NAME
=
${
USER
}
_kernel
echo
${
KERNEL_NAME
}
```
%% Cell type:markdown id: tags:
*
Set directory for kernels virtual environment
-
change if you like
%% Cell type:code id: tags:
```
bash
export
KERNEL_VENVS_DIR
=
${
PROJECT
}
/
${
USER
}
/jupyter/kernels/
mkdir
-p
${
KERNEL_VENVS_DIR
}
echo
${
KERNEL_VENVS_DIR
}
```
%% Cell type:markdown id: tags:
*
Set location of kernel spec
-
select one:
-
personal kernel = "
\$
{HOME}/.local/"
-
project kernel = "
\$
{PROJECT}/.local/"
%% Cell type:code id: tags:
```
bash
export
KERNEL_SPECS_DIR
=
${
HOME
}
/.local/
#export KERNEL_SPECS_DIR=${PROJECT}/.local/
echo
${
KERNEL_SPECS_DIR
}
```
%% Cell type:markdown id: tags:
---
%% Cell type:markdown id: tags:
## 1. Create/Pimp new virual Python environment
%% Cell type:markdown id: tags:
*
1.1 - Load required modules
%% Cell type:code id: tags:
```
bash
module
-q
purge
module
-q
use
$OTHERSTAGES
module
-q
load Stages/Devel-2019a 2> /dev/null
module
-q
load GCCcore/.8.3.0 2> /dev/null
module
-q
load Jupyter
```
%% Cell type:markdown id: tags:
*
1.2 - Load extra modules you need for your kernel
%% Cell type:code id: tags:
```
bash
# module load <module you need>
```
%% Cell type:markdown id: tags:
*
1.3 - Create and activate a virtual environment for the kernel
and ensure python packages installed in the virtual environment are always prefered
%% Cell type:code id: tags:
```
bash
python
-m
venv
--system-site-packages
${
KERNEL_VENVS_DIR
}
/
${
KERNEL_NAME
}
source
${
KERNEL_VENVS_DIR
}
/
${
KERNEL_NAME
}
/bin/activate
export
PYTHONPATH
=
${
VIRTUAL_ENV
}
/lib/python3.6/site-packages:
${
PYTHONPATH
}
echo
${
VIRTUAL_ENV
}
```
%% Cell type:markdown id: tags:
*
1.4 - Install Python libraries required for communication with Jupyter
%% Cell type:code id: tags:
```
bash
pip
install
--ignore-installed
ipykernel
```
%% Cell type:markdown id: tags:
*
1.5 - Install whatever else you need in your Python virtual environment (using pip)
%% Cell type:code id: tags:
```
bash
#pip install <python-package you need>
```
%% Cell type:markdown id: tags:
---
%% Cell type:markdown id: tags:
## 2. Create/Edit launch script for the Jupyter kernel
%% Cell type:markdown id: tags:
*
2.1 - Create launch script, which loads your Python virtual environment and starts the ipykernel process inside:
%% Cell type:code id: tags:
```
bash
echo
'#!/bin/bash
# Load required modules
module purge
module load $OTHERSTAGES'
"
module load Stages/Devel-2019a
module load GCCcore/.8.3.0
module load Jupyter
# Load extra modules you need for your kernel (as you did in step 1.2)
#module load <module you need>
# Activate your Python virtual environment
source
${
KERNEL_VENVS_DIR
}
/
${
KERNEL_NAME
}
/bin/activate
# Ensure python packages installed in the virtual environment are always prefered
export PYTHONPATH=
${
VIRTUAL_ENV
}
/lib/python3.6/site-packages:"
'${PYTHONPATH}'
"
exec python -m ipykernel "
'$@'
>
${
VIRTUAL_ENV
}
/kernel.sh
chmod
+x
${
VIRTUAL_ENV
}
/kernel.sh
```
%% Cell type:markdown id: tags:
---
%% Cell type:markdown id: tags:
## 3. Create/Edit Jupyter kernel configuration
%% Cell type:markdown id: tags:
*
3.1 - Create Jupyter kernel configuration directory and files
%% Cell type:code id: tags:
```
bash
python
-m
ipykernel
install
--name
=
${
KERNEL_NAME
}
--prefix
${
KERNEL_SPECS_DIR
}
```
%% Cell type:markdown id: tags:
*
3.2 - Adjust kernel.json file
%% Cell type:code id: tags:
```
bash
mv
${
KERNEL_SPECS_DIR
}
/share/jupyter/kernels/
${
KERNEL_NAME
}
/kernel.json
${
KERNEL_SPECS_DIR
}
/share/jupyter/kernels/
${
KERNEL_NAME
}
/kernel.json.orig
echo
'
{
"argv": [
"'
${
KERNEL_VENVS_DIR
}
/
${
KERNEL_NAME
}
/kernel.sh
'",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "'
${
KERNEL_NAME
}
'",
"language": "python"
}'
>
${
KERNEL_SPECS_DIR
}
/share/jupyter/kernels/
${
KERNEL_NAME
}
/kernel.json
```
%% Cell type:markdown id: tags:
---
This diff is collapsed.
Click to expand it.
PythonPackages.ipynb
+
248
−
240
View file @
55cc79f0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment