3

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 Answers2

9

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++ !!

abu_bua
  • 1,361
  • 17
  • 25
  • 1
    Thank you for the answer. It indeed seems to work, I am probably doing something wrong. Trying to replicate your steps, when I run a cell I always get a notification with "Connecting to kernel:C++14" which immediately changes to "Canceled". Do you know what the problem might be? – Horia Turcuman Apr 08 '21 at 20:09
  • Thanks, it works now! As I understand, the problem is that vscode does not properly start or connect to the local notebook server? – Horia Turcuman Apr 12 '21 at 15:00
  • yes, seem so. however, i prefer to start the notebook this way as i have full control over extensions, ... – abu_bua Apr 12 '21 at 15:08
3

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!

HDubz
  • 167
  • 1
  • 2
  • 14
  • How can you change the cell language mode to c++ in vscode? In my jupyter notebook there seems to be no option for cpp – William Le Dec 16 '22 at 16:00
  • The code cell language will change by selecting the kernel in the upper right corner. – HDubz Feb 18 '23 at 18:25