# Install Xeus-Cling in a CoCalc project By [Samuel Lelièvre](http://carva.org/samuel.lelievre) This document gives instructions for installing the **Xeus-Cling C++ Jupyter kernels** in a CoCalc project. The outline is: - Brief presentation of Xeus-Cling and CoCalc - Installation guide in three simple steps - Quick start to use the installed kernels ## What is Xeus-Cling, what is CoCalc ### Xeus-Cling **Xeus-Cling** provides kernels for [**Project Jupyter**](https://jupyter.org/) enabling the **C++** programming language in the Jupyter notebook. - Source code: https://github.com/QuantStack/xeus-cling - Documentation: https://xeus-cling.readthedocs.io Xeus-Cling relies on the [**Cling C++ interpreter**](https://root.cern.ch/cling) from CERN, and the [**Xeus library**](https://github.com/QuantStack/xeus), a native implementation of the Jupyter kernel protocol. ### CoCalc [**CoCalc**](https://cocalc.com/index.html) (for "Collaborative Calculation in the Cloud") is a sophisticated online environment for - Mathematical calculation: SageMath, GAP, SymPy, Maxima, ..., - Statistics and Data Science (R Project, Pandas, Statsmodels, Scikit-Learn, TensorFlow, NLTK, …), - Document authoring (LaTeX, Markdown/HTML, ...), - General purpose computing (Python, Octave, Julia, Scala, ...). ### System-wide install of Xeus-Cling 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](https://github.com/sagemathinc/cocalc/issues/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 Xeus-Cling into an Anaconda environment in our CoCalc project - install the kernels for Jupyter from there ### Install Xeus-Cling using Conda Run the following in the terminal ~$ anaconda3 (base) ~$ conda create -n boo xeus-cling -c QuantStack ### 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: (base) ~$ jupyter kernelspec install --user .conda/envs/boo/share/jupyter/kernels/xeus-cling-cpp11 [InstallKernelSpec] Installed kernelspec xeus-cling-cpp11 in /home/user/.local/share/jupyter/kernels/xeus-cling-cpp11 (base) ~$ jupyter kernelspec install --user .conda/envs/boo/share/jupyter/kernels/xeus-cling-cpp14 [InstallKernelSpec] Installed kernelspec xeus-cling-cpp14 in /home/user/.local/share/jupyter/kernels/xeus-cling-cpp14 We can now exit Anaconda: (base) ~$ conda deactivate ## Testing / using our installation To test that everything went well, we open a Jupyter notebook worksheet in our CoCalc project. In the "Kernel > Change Kernel" menu item in the worksheet, we should see two new kernels called **C++11** and **C++14**. If not, use the "Kernel > Refresh Kernel List" menu item. ![CoCalc: Refresh Kernel List](img/scr_2018-05-04T035454Z.png) Once they appear, change to the "C++11" kernel, which should appear towards the top of the list of available kernels. ![Select the (xeus) "C++11" kernel in Jupyter in CoCalc](img/scr_2018-05-04T035519Z.png) 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](img/scr_2018-02-06T065536Z.png) See [example Jupyter notebook worksheet running the xeus-cling kernel](https://cocalc.com/share/4711033a-b5d8-4fb3-9708-e9019ba1c158/Try-xeus-cling-kernel-Jupyter-notebook-CoCalc.ipynb?viewer=share). ----- **Acknowledgements** Thanks to [**QuantStack**](http://quantstack.net) 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**](http://opendreamkit.org), "Horizon 2020" "European Research Infrastructures" project #676541. Thanks to Sylvain Corlay for making the installation [one step simpler](https://github.com/QuantStack/xeus-cling/pull/117), after a first version of this document was published. Thanks to the organisers of the [Workshop on interfacing scientific software with low-level libraries](https://github.com/OpenDreamKit/OpenDreamKit/issues/251), held in Cernay-la-Ville, 30 April -> 05 May 2018, where this second take on the installation was done, resulting in simpler instructions than [the first take which suggested starting by installing Miniconda](https://cocalc.com/share/4711033a-b5d8-4fb3-9708-e9019ba1c158/Try-xeus-cling-kernel-Jupyter-notebook-CoCalc.ipynb?viewer=share).