Skip to content

Last updated:2026-10-12

Interactive C++ in Jupyter Notebook

In Python, we can use Jupyter Notebook to see results directly, for example:

l = [1,2]
l

It directly outputs:

[1,2]

But when using C++, for example:

map<string, int> mp{
    {"one",   1},
    {"two",   2},
    {"three", 3},
    {"four",  4}
};

To print it you would have to loop over it — couldn't we just print the result directly?

So easy!!! Jupyter Notebook can solve everything, haha~

How to Play with C++ in Jupyter?

There is a repository on GitHub, shown below:

https://github.com/QuantStack/xeus-cling

xeus-cling is a Jupyter kernel for C++, based on a native implementation of the C++ interpreter and the Jupyter protocol xeus.

Currently, it supports macOS and Linux, but not Windows.

Installation is also very simple: first install Anaconda, then create a virtual environment inside it:

conda create -n cling

Switch into it:

conda activate cling

Install jupyter and notebook for the new environment:

conda install jupyter notebook

Install xeus-cling using conda-forge:

conda install xeus-cling -c conda-forge

To speed up installation, remember to configure a package mirror for Anaconda!

Check whether the kernel is installed:

jupyter kernelspec list

Output:

python3    /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/python3
xcpp11     /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp11
xcpp14     /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp14
xcpp17     /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp17

Open Jupyter Notebook and you will see the kernel.

Start Jupyter Notebook:

jupyter-notebook

How to Play with C in Jupyter?

You only need to install a C kernel!

You can create the C kernel directly in the current environment, or set up a new environment for it; below we install it directly in the current environment.

pip install jupyter-c-kernel
install_c_kernel
jupyter kernelspec list

Now it outputs:

c          /home/light/anaconda3/envs/cling/share/jupyter/kernels/c
python3    /home/light/anaconda3/envs/cling/share/jupyter/kernels/python3
xcpp11     /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp11
xcpp14     /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp14
xcpp17     /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp17

Start Jupyter Notebook:

jupyter-notebook

Comments