| Hosted by CoCalc | Download

Install Xeus-Cling in a CoCalc project

This document gives instructions for installing the Xeus-Cling C++ Jupyter kernels in a CoCalc project.

The outline is:

  • Brief presentation of Xeus-Cling

  • Installation guide in three simple steps

  • Quick start to use the installed kernels

What is Xeus-Cling

Xeus-Cling provides kernels for Project Jupyter enabling the C++ programming language in the Jupyter notebook.

Xeus-Cling relies on the Cling C++ interpreter from CERN, and the Xeus library, a native implementation of the Jupyter kernel protocol.

System-wide install on CoCalc coming soon

Due to a minor obstacle, Xeus-Cling is so far not installed system-wide in CoCalc. Solving that is tracked at CoCalc issue #2324. The transition to Ubuntu 18.04, planned for May-June 2018, will hopefully solve the issue.

However, it is possible to install Xeus-Cling manually in a CoCalc project, following the instructions below.

Installing Xeus-Cling in a CoCalc project

The solution we propose is to

  • install Miniconda in our CoCalc project

  • use Conda to install the Xeus-Cling package in Miniconda

  • install the kernels for Jupyter

Install Miniconda

About Miniconda3:

The first step is to download Miniconda. by typing the following in a CoCalc terminal:

REMOTE='https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh' SCRIPT='Miniconda3.sh' curl -o $SCRIPT $REMOTE

Once the download is complete, we run the installation script by typing the following in our CoCalc terminal:

bash Miniconda3.sh

and then following the instructions that script gives, which will amount to:

  • press ENTER

  • scroll down the license agreement by hitting the SPACE key

  • type "yes" then press ENTER to accept license agreement

  • choose installation location; say default, ie /home/user/miniconda

  • type "yes" to prepend the install location to PATH in .bashrc

Once that is done, we need to update our PATH, in one of two ways: close and re-open the terminal, or run this command in the terminal:

source .bashrc

Install Xeus-Cling using Conda

Run the following in the terminal

conda install xeus-cling -c QuantStack -c conda-forge

Optionally, you can also install xwidgets to enable Jupyter interactive widgets in the C++ kernel, by running:

conda install xwidgets -c QuantStack -c conda-forge

Note that this optional extra install will only work in the "Plain Jupyter" server, which you can launch by going to the CoCalc project's "settings" tab, and scrolling to the very bottom, and clicking "Plain Jupyter Server".

Install the kernels for Jupyter

The last step of our installation is to make Jupyter aware of the new kernels, by installing them in the appropriate location.

For this, it suffices to run the following in our CoCalc terminal:

jupyter kernelspec install --user miniconda3/share/jupyter/kernels/xeus-cling-cpp11 jupyter kernelspec install --user miniconda3/share/jupyter/kernels/xeus-cling-cpp14

Testing / using our installation

To test that everything went well, we open a Jupyter notebook worksheet in our CoCalc project.

Using the "Kernel > Change Kernel" menu item in the worksheet, we change to the "xeus C++11" kernel, which should appear towards the end of the list of available kernels.

Select the "xeus C++11" kernel in Jupyter in CoCalc

If a "Not trusted" indication appears near the kernel name at the top right of the worksheet, click these words and change the setting to "Trusted".

In a code cell, type some C++11 code, for example:

int i = 1; i + 3

then evaluate the cell!

Evaluate C++11 code cell in Jupyter notebook worksheet running "xeus-cling" kernel in CoCalc

See example Jupyter notebook worksheet running the xeus-cling kernel.


Acknowledgements

Thanks to QuantStack for developing the xeus-cling Jupyter kernels for C++11 and C++14!

Exploring this topic as well as writing and publishing this installation guide and example worksheet was facilitated by

  • CoCalc project upgrades (internet access, member hosting) for development, kindly provided by SageMath Inc.

  • financial support from OpenDreamKit, "Horizon 2020" "European Research Infrastructures" project #676541.

Thanks to Sylvain Corlay for making the installation one step simpler, after a first version of this document was published.