Custom Environment
Adding Python Packages and Creating Custom Environments¶
Many commonly used Python packages are preinstalled in the provided images. If additional packages are needed, they can be installed manually.
There are two ways to add additional Python packages:
1. Using Pip¶
You can install Python packages directly within a Jupyter notebook by running the following command in a code cell:
!pip install package_name
package_name package in the current environment. Using pip is particularly suitable for simple installations or for packages that are not available via Conda. 2. Using Conda¶
Many default system directories are read-only, so you won’t be able to directly install packages into the base environment. Instead, you can create a new conda environment (see the section below for instructions) where you can install and manage your own packages.
Create new conda environment as a kernel in JupyterHub¶
Prerequisites¶
Before installing new packages, you need to initialize your shell for conda. This step ensures that conda commands work properly in your terminal. To do this, open a terminal and run the following commands:
conda init
bash
Installation¶
To create a new conda environment with Python 3.11 and the pandas package, follow these steps. The ipykernel package is also required to use this environment as a kernel in Jupyter. 1. Open a terminal in JupyterHub. 2. Create the environment by running:
conda create --name py311 python=3.11 ipykernel pandas -y
conda activate py311
python -m ipykernel install --user --name py311 --display-name "Python (py311)"
The new environment should now be available as a selectable kernel when you open or create a new notebook.
Key Points to Note:
- Conda init is required only once to set up your shell for conda.
- You can replace py311, pandas, or the Python version with your desired environment name, packages, or Python version.
- The kernel name "Python (py311)" is the name that will appear in Jupyter when selecting the kernel. You can customize it to any name you prefer.
Running Commands and GUI Applications in the Terminal¶
You can also run any command or script by opening a terminal in JupyterHub. As a user, you have permissions to run files with your user privileges.
JupyterHub NRW also provides an X11 terminal (Konsole) that allows you to access GUI-based applications as well. This enables you to run programs that require a graphical interface, such as scientific software, visual tools, or data visualization applications.