简体   繁体   中英

cling on Jupyter on Windows: Kernel cannot start

Background : I am trying to install the cling c++ interpreter here . I am on a Windows and have had Anaconda running well, Jupyter notebook also working fine with the existing Python kernels. The installation process was smooth on the surface but there is Kernel error once I try to open Jupyter notebook on the installed Kernel.

(In the end I would hope to be able to use c++ with Jupyter notebook so if anyone has had any success please could you share your experience. On that, while the xeus-cling is not usable for Windows as many say, this cling appears to be a separate thing)

The installation : Here is what I have done:

  1. Download the binary cling_2019-11-28_arm64.tar.bz2 (is this correct for Windows?) from https://root.cern.ch/download/cling/
  2. Extract and place in Program Files folder
  3. Following the instruction in here , add C:\\Program Files\\cling_2019-11-28_arm64\\bin to the PATH variable
  4. Activate base Anaconda environment
  5. cd .../share/cling/Jupyter/kernel
  6. pip install -e .
  7. jupyter-kernelspec install --user cling-cpp11

Every thing seems to be fine up to here, no warning/error.

The error: Then I load up my Jupyter notebook and try to run the cpp11 kernel, but it is unable to start with a long error traceback, the first/last items of which read:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\web.py", line 1699, in _execute
    result = await result
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 736, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\sessions\handlers.py", line 73, in post
    type=mtype))
 ... (omitted) ...
  File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\launcher.py", line 138, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

And on the cmd the following:

[E 14:39:14.265 NotebookApp] Failed to run command:
    ['jupyter-cling-kernel', '-f', 'path\\to\\jupyter\\runtime\\kernel-..(random string here)..json', '--std=c++11']

The troubleshooting (1) : ... appearing to suggest that it is unable to locate a jupyter-cling-kernel . But I do have file named jupyter-cling-kernel in the .../Anaconda3/Scripts folder, and this folder is also in my PATH variable. After opening it, I discovered it is a python file with only a few lines. Looks like it corresponds to the command above.

#!C:\ProgramData\Anaconda3\python.exe
# EASY-INSTALL-DEV-SCRIPT: 'clingkernel==0.0.2','jupyter-cling-kernel'
__requires__ = 'clingkernel==0.0.2'
__import__('pkg_resources').require('clingkernel==0.0.2')
__file__ = 'C:\\Program Files\\cling_2019-11-28_arm64\\share\\cling\\Jupyter\\kernel\\scripts\\jupyter-cling-kernel'
with open(__file__) as f:
    exec(compile(f.read(), __file__, 'exec'))

so then I modified my kernel.json file, adding the absolute python path (so that it knows to run it with python) and the absolute path of the jupyter-cling-kernel. (originally it was just "argv:["jupyter-cling-kernel", "-f", ... )

{
  "display_name": "C++11",
  "argv": [
      **"C:\\ProgramData\\Anaconda3\\python.exe",
      "C:\\ProgramData\\Anaconda3\\Scripts\\jupyter-cling-kernel",**
      "-f",
      "{connection_file}",
      "--std=c++11"
  ],
  "language": "C++"

}

The troubleshooting (2) :... which indeed appears to be the right direction, at least it is running sth but now another error:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\Scripts\jupyter-cling-kernel", line 7, in <modu
le>
    exec(compile(f.read(), __file__, 'exec'))
  File "C:\Program Files\cling_2019-11-28_arm64\share\cling\Jupyter\kernel\scrip
ts\jupyter-cling-kernel", line 3, in <module>
    from clingkernel import main
  File "c:\program files\cling_2019-11-28_arm64\share\cling\jupyter\kernel\cling
kernel.py", line 24, in <module>
    from fcntl import fcntl, F_GETFL, F_SETFL
ModuleNotFoundError: No module named 'fcntl'

Now with some googling this fcntl appears to be sth not for Windows. So at this point I am wondering have I downloaded the wrong binary or should I modify this clingkernel.py file or do I need to do some compilation myself?

Again, if any of you knows of how to get the c++ run of Jupyter (on windows), appreciate if you could share your experience. Thanks.

The cling interpreter has been packaged for conda-forge.

You can simply run

conda install cling -c conda-forge

and then run cling . However, unfortunately, the Jupyter kernel is not included with that build, and the windows build has some issues with IO operations which I am currently investigating.

With Windows 10 + WSL, we can install xeus-cling for C++ on Windows

Steps includes

  1. Enable Ubuntu on WSL
  2. Install Miniconda
  3. Setup Conda, Jupyter Notebook, Xeus-Cling

This cling notebook with the cpp environment can be made to run from a desktop shortcut. Steps are documented on C/C++ Jupyter Notebook using xeus-cling - Windows WSL Setup

也许尝试通过按 o(not 0) 两次来重新启动内核。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM