Installing software

We’ll use LangChain, an open-source library for making applications with LLMs. We’ll use models from HuggingFace, a website that has tools and models for machine learning.

Exercise: Create a new notebook

Create a new Jupyter Notebook called installing by clicking the File-menu in JupyterLab, and then New and Notebook. If you are asked to select a kernel, choose “Python 3”. Give the new notebook a name by clicking the File-menu in JupyterLab and then clicking Rename Notebook. Use the name installing.

Warning

If you usually work with virtual environments, you should setup and activate a virtual environment before you continue, see Virtual Environments. If you haven’t heard of virtual environments, you can continue without using virtual environments. In that case, jump to Python packages.

Virtual Environments

Venv is a module in Python that supports creating independent virtual environments (venv). The venv has its base in the existing python installation.

Creating a virtual environment

The command below will create a venv on the project directory. We are doing this from Jupyter lab:

!python -m venv .venv

Activating the environment from the commandline

## Terminal from jupyter lab:
source .venv/bin/activate

JupyterLab kernel for the environment

! .venv/bin/python -m ipykernel install --user --name LLM --display-name "Python (LLM)"

Python packages

We will use the python package manager pip for installing software. pip installs software from the Python Package Index. First, we update pip to the newest version:

pip install --upgrade pip

Requirements file

In December 2025, while doing preparations for a course, we had some issues due to the fact that some of our most important libraries are deprecated. This led us to implement a requirements file. At this stage, we need the exact dependencies from the file LLM-requirements.txt. As you can read from the file, the technical issues are solved through naming a library like this: “langchain==1.2.1”, rather than just “langchain”. Run the code below:

pip install -r /fp/projects01/ec443/LLM-requirements.txt

Model location

We want to tell the HuggingFace library where to store its data. The path below is for the Educloud/Fox project ec443.

import os
os.environ['HF_HOME'] = '/fp/projects01/ec443/huggingface/cache/'

Optional::

If you run on your own, or want to download a model that is not previously used by the group, you will need to make an account at Huggingface, and store the token you get. Your token can be found under your profile, in the right side of the top menu: “access tokens”. For the gated models, you need to apply, before you can download. Your token should be stored in a safe place, and not shared with anyone.

Cell for entering your HF token:

from huggingface_hub import login
login()