This README explains how to set up a Python environment using Miniconda in order to run the Jupyter notebooks
The environment will include:
- Python 3.12 (or comparable 3.x version)
jupyter/jupyterlab- The
cryptographypackage with PQC algorithms support.
If you do not already have Miniconda installed:
- Download Miniconda for your platform from the official website.
- Run the installer and follow the prompts.
- Open a new terminal so the
condacommand is available.
On macOS / Linux, you can usually verify with:
conda --versionOn Windows, use the Anaconda Prompt or a terminal where conda is on the PATH.
Create a dedicated environment for ML-KEM experiments. In this example we call it cryptography-pqc,
but you can choose any name you like.
conda create -n cryptography-pqc python=3.12 -yActivate the environment:
conda activate cryptography-pqcYou should now see (cryptography-pqc) (or your chosen name) in your shell prompt.
Inside the activated environment, install Jupyter.
# Jupyter Notebook or JupyterLab
conda install -y jupyterlabNote that liboqs-python cannot be installed durectly via pip or conda. See OQS github for installation instrucations
Note: Make sure you are still inside the
cryptography-pqcenvironment when you runpip, otherwise you may install into a different Python environment than intended.
The cryptography package uses a backend (commonly OpenSSL) to provide cryptographic primitives.
Newer versions expose ML-KEM (Kyber) through the KEM API. To verify, you can start a Python REPL
and try:
from cryptography.hazmat.primitives.kem import MLKEM768If this import works without errors, you have ML-KEM support available.
From the directory where the notebook is located, run:
conda activate cryptography-pqc
jupyter labor, if you prefer the classic notebook interface:
conda activate cryptography-pqc
jupyter notebookA browser window should open. Navigate to the chosen notebook and open it.
Inside Jupyter:
- Select the
Kernelmenu (if available) and ensure it uses the Python kernel from yourcryptography-pqcenvironment. - Run the cells in order (e.g.,
Run All), or step through them one by one.
The notebook will:
- Check your environment (
Python,cryptography, ML-KEM support) - Demonstrate key generation, encapsulation, and decapsulation
- Provide a simple benchmark
- Give a high-level mathematical explanation of ML-KEM
If you need to update packages later, you can run:
conda activate cryptography-pqc
conda update cryptography jupyterlabIf your environment becomes inconsistent, you can remove and recreate it:
conda deactivate
conda env remove -n cryptography-pqc
conda create -n cryptography-pqc python=3.11 -y
conda activate cryptography-pqc
conda install -y jupyterlab cryptography-
ModuleNotFoundError: No module named 'cryptography'Ensure your environment is activated (
conda activate cryptography-pqc) before starting Jupyter. -
Import error for
MLKEM768Your installed version of
cryptographymay be too old or built against a backend that does not expose ML-KEM. Try updating the package:conda activate cryptography-pqc conda update cryptography
-
Jupyter uses the wrong Python environment
Start Jupyter from within the activated environment, or explicitly configure a kernel via:
python -m ipykernel install --user --name cryptography-pqc --display-name "Python (cryptography-pqc)".
Once everything is working, you should be able to run the ML-KEM notebook end-to-end.