vgvassilev / cling

The interactive C++ interpreter Cling
https://rawgit.com/vgvassilev/cling/master/www/index.html
Other
1.77k stars 102 forks source link

Jupyter C++ kernel dies repeatedly #171

Open Yancey2126 opened 6 years ago

Yancey2126 commented 6 years ago

I installed cling and libgcc following this article: http://shuvomoy.github.io/blog/programming/2016/08/04/Cpp-kernel-for-Jupyter.html

However, after running jupyter notebook, I can see C++ except that the kernel can never start and died repeatedly.

KernelRestarter: restarting kernel (4/5) kernel 8d8df6db-061d-4d07-87f4-b230de31a007 restarted Traceback (most recent call last): File "/usr/local/bin/jupyter-cling-kernel", line 6, in <module> exec(compile(open(__file__).read(), __file__, 'exec')) File "/Users/yangchen/Desktop/C++/clingMac/share/cling/Jupyter/kernel/scripts/jupyter-cling-kernel", line 4, in <module> main() File "/Users/yangchen/Desktop/C++/clingMac/share/cling/Jupyter/kernel/clingkernel.py", line 354, in main ClingKernelApp.launch_instance() File "/Library/Python/2.7/site-packages/traitlets/config/application.py", line 657, in launch_instance app.initialize(argv) File "<decorator-gen-121>", line 2, in initialize File "/Library/Python/2.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error return method(app, *args, **kwargs) File "/Library/Python/2.7/site-packages/ipykernel/kernelapp.py", line 457, in initialize self.init_kernel() File "/Library/Python/2.7/site-packages/ipykernel/kernelapp.py", line 368, in init_kernel user_ns=self.user_ns, File "/Library/Python/2.7/site-packages/traitlets/config/configurable.py", line 412, in instance inst = cls(*args, **kwargs) File "/Users/yangchen/Desktop/C++/clingMac/share/cling/Jupyter/kernel/clingkernel.py", line 100, in __init__ clingInPath = shutil.which('cling') AttributeError: 'module' object has no attribute 'which' [W 13:44:34.272 NotebookApp] KernelRestarter: restart failed

I have no idea what is going on.

dabro commented 6 years ago

TL;DR: use Python 3.3 or higher.

Python 2.7 doesn't have which method on shutil. See https://stackoverflow.com/questions/9877462/is-there-a-python-equivalent-to-the-which-command .

There used to be code that would catch this:

        except AttributeError:
            from distutils.spawn import find_executable
            whichCling = find_executable('cling')

and default to find_executable, but that seems to have been dropped in the last couple revisions. Specifically: https://github.com/vgvassilev/cling/commit/3848d29556d4bceb212ecde82b941aa2e26d8be7#diff-86d66e408680d0ec46117add5d297db7 lines 111-113 Maybe it didn't work? You could try adding it back and move the try: from line 107 of the most recent commit to line 100:

def __init__(self, **kwargs):
         super(ClingKernel, self).__init__(**kwargs)

         try:
           clingInPath = shutil.which('cling')
           if not clingInPath:
               from distutils.spawn import find_executable
               clingInPath = find_executable('cling')
           if not clingInPath:
               raise RuntimeError('Cannot find cling in $PATH. No cling, no fun.')

           whichCling = os.readlink(clingInPath)
           whichCling = os.path.join(os.path.dirname(clingInPath), whichCling)
         except OSError as e:
             #If cling is not a symlink try a regular file
             #readlink returns POSIX error EINVAL (22) if the
             #argument is not a symlink
             if e.args[0] == 22:
                whichCling = clingInPath
             else:
                 raise e
        except AttributeError:
            from distutils.spawn import find_executable
            whichCling = find_executable('cling')
yiyang186 commented 6 years ago

I corrected it: clingInPath = 'path/to/cling' ... it works, but urgly.