Running C++ Jupiter Notebook in VSCode Insiders

8.6k Views Asked by At

I have installed xeus, xeus-cling and jupyter extension. I changed the kernel to one of the C++ versions, the cell language to C++ but when I click run the cell never outputs. Can someone please help me solve this?

2

There are 2 best solutions below

3
abu_bua On BEST ANSWER

Running xeus-cling under vs-code

enter image description here

Ceus works in the vs-code environment. You have to activate your conda environment and invoke vs-code from it (i use the code insiders edition). In linux this looks like

conda activate xeus-cling # my env for xeus-cling; where i compiled cling

then invoke code (insiders) in your project directory

code-insiders .& # or code .& if you are using the stable version

If you have still problems try the following:

  • start a jupyter notebook from command line (of course in your conda environment described above)

     jupyter notebook --no-browser
    

    Copy or remember the line with the token, which looks like http://127.0.0.1:8888/?token=8daf8f57bef55918defb467defc55f0305803caa27dd01d2

  • next go to code-insiders and click on the bottom bar Jupyter Server: Remote enter image description here

  • on the top of the window a list will pop up, looking like

enter image description here

  • select Existing or copy the token into it

  • now a message should appear reload kernel , click on the button to do so

  • in the bottom bar select the kernel to e.g. C++14

  • create a new blank jupyter worksheet and don't forget to change the cell to C++ !!

2
HDubz On

Heres a solution without having to activate the conda environment. The following commands are what worked on ubuntu:focal

Update conda:

conda update conda --yes

Create the environment to install xeus-cling kernel:

conda create -n xeus-cling --yes

Install xeus-cling kernel in the xeus-cling environment created earlier:

conda install xeus-cling -c conda-forge -n xeus-cling --yes

Find where your conda environments are installed by looking for envs directories in the output of the following command:

conda info

My conda environments were located in /etc/miniconda/envs. Thus there will be a subdirectory for each environment which holds all the installed packages. The kernels are located in xeus-cling/share/jupyter/kernels. The path starts with xeus-cling because that's what we named the conda environment earlier.

Inside of the kernels/ directory you will find a few c++ kernels. To install the conda xeus-cling kernel directly into Jupyter do the following:

jupyter kernelspec install /etc/miniconda/envs/xeus-cling/share/jupyter/kernels/xcpp11 --sys-prefix
jupyter kernelspec install /etc/miniconda/envs/xeus-cling/share/jupyter/kernels/xcpp14 --sys-prefix
jupyter kernelspec install /etc/miniconda/envs/xeus-cling/share/jupyter/kernels/xcpp17 --sys-prefix

Open VS Code as you normally would. No need to activate the conda environment. Create a new Jupyter Notebook. Finally, make sure you select the C++ Kernel in the upper right corner of the screen.

VS Code select kernel

I used @abu_bua answer above and these docs from the xeus-cling project to figure this out. I hope this helps.

Happy coding!