If for some reason you do not want to use the "Custom Packages" component you can of course use miniconda manually.
( In step 6 of this tutorial you will need sudo rights. If you do not have them, talk to the owner of the workspace or to an admin of the collaboration.)
Step 1: Get Miniconda
Go to https://docs.conda.io/en/latest/miniconda.html#linux-installers to make sure you have the current link to download the installation script.
Use the link for "Miniconda3 Linux 64-bit" and "latest".
Start a terminal in the JupyterLab dashboard.
Download the installation script.
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
Step 2: Install Miniconda
Run the installation script.
("-b" skips all confirmations with "yes")
bash Miniconda3-latest-Linux-x86_64.sh -b
Initialize conda.
~/miniconda3/bin/conda init
Close the current terminal and start a new one.
Check that conda has been installed: the shell prompt should start with the name of the currently active conda-envrionment.
By default this is "(base)".
Try the version parameter.
(base) username@hostname:~$ conda --version conda 4.10.3
The actual version, of course, can differ.
Accept the terms of service (tos) for all used channels. Anaconda requires these to get accepted for all used channels. This not a technical but a legal requirement.
conda tos accept
Update conda.
conda update conda -y
Step 3: Create a virtual conda-environment
Create a virtual environment. Here you can already include some packages, even with desired version (for instance the pandas package of version 3.0.5: "pandas=3.0.5", or just "pandas" for the default/latest version).
("--yes" to confirm all choices upfront)
conda create --yes --name pandas3 pandas=3.0.5
Step 4: Activate the environment
Activate the environment.
conda activate pandas3
Now the prompt should change to
(pandas3) username@hostname:~$
For the next steps, do switch back to the (base) environment. (Because ipykernel should not necessarily be installed in each environment):
conda deactivate
Now the creation of the virtual environment is finished. The next steps are about creating a Jupyter-kernel to make the environment usable for Notebooks.
Step 5: Create a kernel from the environment
If you want to use your environment as a Jupyter-kernel, you can continue with this step.
Install the ipykernel tool to the (base) environment.
conda install --yes --channel anaconda ipykernel
Run the ipykernel tool. The display name will identify your environment/kernel in Jupyter Notebooks.
python3 -m ipykernel install --user --name pandas3 --display-name "Py Pandas 3"
You can inspect the environment using the "jupyter" command from the jupyter-client apt-package:
jupyter kernelspec list
Step 6: Allow the kernel to be shown in the Jupyter launcher
Not all existing kernels on the machine should be used for coding.
Doing so would risk the workspace's system python to become corrupt and render the entire workspace unusable.
So we have one more step left, which is to explicitly allow the new environment to be used for Jupyter Notebooks.
Which kernels can be used in Notebooks is controlled by the jupyterhub_config.py file.
If you want to be sure that you can go back after your changes, make a copy of this file first.
cp /etc/jupyter/jupyter_config.py /etc/jupyter/jupyter_config.py.bak
Use an editor like nano or vim to edit the file:
sudo nano /etc/jupyter/jupyter_config.py
Add a line to the following part of the python code, there:
c.Spawner.args = [
"--KernelSpecManager.ensure_native_kernel=False",
"--KernelSpecManager.allowed_kernelspecs", "src-default",
"--KernelSpecManager.allowed_kernelspecs", "pandas3",
]
The third line here, between the brackets, adds the new "pandas3" kernel to the allowed kernels.
Restart the jupyterhub service to let the changes take effect:
sudo systemctl restart jupyterhub
After a short moment, access the Jupyter Notebook workspace again through the Research Cloud portal (this is more comfortable than trying to get the current browser tab of Jupyter working again).
If Juypter does not come up again, you might have made a typo when editing the config file. In that case, check the indentation, quotes and commas.
Step 7: Use the new kernel
In JupyterLab, start a launcher tab. See that Notebooks or Consoles can be started with the new kernel.
Also existing Notebooks can switch to the new kernel with the dropdown list on the top right of the page.
Using conda to the full
Conda can do a lot. Environments can be exported and used for creating new instances of a particular configuration.
This is a great help when collaborating with other developers.
But these features are outside the scope of this manual.
Please refer to https://docs.conda.io/en
https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html
or one of the countless other tutorials out there.
