root-project / cling

The cling C++ interpreter
Other
3.4k stars 267 forks source link

libclingJupyter is installed in wrong directory by CMake #10

Closed dabro closed 6 years ago

dabro commented 8 years ago

After troubleshooting the following:

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/browneej/workspace/cling/src/tools/cling/tools/Jupyter/kernel/scripts/jupyter-cling-kernel", line 4, in <module>
    main()
  File "/Users/browneej/workspace/cling/src/tools/cling/tools/Jupyter/kernel/clingkernel.py", line 290, in main
    ClingKernelApp.launch_instance()
  File "/usr/local/lib/python3.5/site-packages/traitlets/config/application.py", line 588, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-122>", line 2, in initialize
  File "/usr/local/lib/python3.5/site-packages/traitlets/config/application.py", line 74, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/ipykernel/kernelapp.py", line 421, in initialize
    self.init_kernel()
  File "/usr/local/lib/python3.5/site-packages/ipykernel/kernelapp.py", line 360, in init_kernel
    user_ns=self.user_ns,
  File "/usr/local/lib/python3.5/site-packages/traitlets/config/configurable.py", line 404, in instance
    inst = cls(*args, **kwargs)
  File "/Users/browneej/workspace/cling/src/tools/cling/tools/Jupyter/kernel/clingkernel.py", line 87, in __init__
    if not self.libclingJupyter:
AttributeError: 'ClingKernel' object has no attribute 'libclingJupyter'

I found libclingJupyter.dylib in /usr/local/lib/clang/lib/ instead of /usr/local/lib/cling/lib, where the system expected it:

def __init__(self, **kwargs):
        super(ClingKernel, self).__init__(**kwargs)
        whichCling = shutil.which('cling')
        if whichCling:
            clingInstDir = os.path.dirname(os.path.dirname(whichCling))
            llvmResourceDir = clingInstDir
        else:
            raise RuntimeError('Cannot find cling in $PATH. No cling, no fun.')

        for ext in ['so', 'dylib', 'dll']:
            libFilename = clingInstDir + "/lib/libclingJupyter." + ext
            if os.access(libFilename, os.X_OK):
                self.libclingJupyter = ctypes.CDLL(clingInstDir + "/lib/libclingJupyter." + ext,
                                                   mode = ctypes.RTLD_GLOBAL)
                break

        if not self.libclingJupyter:
            raise RuntimeError('Cannot find ' + clingInstDir + '/lib/libclingJupyter.{so,dylib,dll}')

https://github.com/root-mirror/cling/blob/master/tools/Jupyter/kernel/clingkernel.py https://github.com/root-mirror/cling/commit/cc2ca03981c993a432942afbc31803fc8a5dc2dd

for me, either which cling in bash or whichCling = shutil.which('cling') in python return /usr/local/lib/cling.

I installed using cmake:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lib/cling -DLLVM_TARGETS_TO_BUILD=CppBackend\;X86 -DCMAKE_BUILD_TYPE=Debug ../src

after removing CBackend\;

Axel-Naumann commented 8 years ago

How would "the system" have put it into /usr/local/lib/clang/lib/ if you configured /usr/local/lib/cling/lib/? I guess this is from an earlier build?

Axel-Naumann commented 7 years ago

No feedback, closing...

mfouesneau commented 7 years ago

Still had the issue when installed as a user. I had to change the clingkernel.py:

        if whichCling:
            clingInstDir = os.path.realpath(shutil.which('cling'))[:-len('/bin/cling')]
            llvmResourceDir = clingInstDir
        else:

The main issue was that the instDir was poluted by the current directory.

Axel-Naumann commented 6 years ago

Is this still an issue after today's update to the "where's my libclingJupyter" logic?

ghost commented 6 years ago

I am still getting the error as well, I can't even find the location of libclingJupyter. Cannot find ' + clingInstDir + '/lib/libclingJupyter.{so,dylib,dll}

mkreim commented 6 years ago

Same problem here. I tried installing a kernel for jupyter via

wget https://raw.githubusercontent.com/root-project/cling/master/tools/packaging/cpt.py
./cpt.py --check-requirements && ./cpt.py --create-dev-env Debug --with-workdir=./cling-build/
cd cling-Ubuntu-16.04-x86_64-0.6~dev-3a5d26e/share/cling/Jupyter/kernel/
pip install -e .
jupyer kernelspec install cling-cpp17 --user

(inside a virtualenv using python 3.6).

If I start jupyter notebook it allows me to start a C++17 kernel. However, the kernel dies immediately.

If I run the kernel manually via commandline it says

$ jupyter-cling-kernel 
NOTE: When using the ipython kernel entry point, Ctrl-C will not work.

To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.

To read more about this, see https://github.com/ipython/ipython/issues/2049

To connect another client to this kernel, use:
    --existing kernel-9898.json
Traceback (most recent call last):
  File "~/.virtualenvs/jupyter/bin/jupyter-cling-kernel", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "~/bin/cling-Ubuntu-16.04-x86_64-0.6~dev-3a5d26e/share/cling/Jupyter/kernel/scripts/jupyter-cling-kernel", line 4, in <module>
    main()
  File "~/bin/cling-Ubuntu-16.04-x86_64-0.6~dev-3a5d26e/share/cling/Jupyter/kernel/clingkernel.py", line 354, in main
    ClingKernelApp.launch_instance()
  File "~/.virtualenvs/jupyter/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-123>", line 2, in initialize
  File "~/.virtualenvs/jupyter/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "~/.virtualenvs/jupyter/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 465, in initialize
    self.init_kernel()
  File "~/.virtualenvs/jupyter/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 376, in init_kernel
    user_ns=self.user_ns,
  File "~/.virtualenvs/jupyter/lib/python3.6/site-packages/traitlets/config/configurable.py", line 412, in instance
    inst = cls(*args, **kwargs)
  File "~/bin/cling-Ubuntu-16.04-x86_64-0.6~dev-3a5d26e/share/cling/Jupyter/kernel/clingkernel.py", line 138, in __init__
    raise RuntimeError('Cannot find ' + clingInstDir + '/lib/libclingJupyter.{so,dylib,dll}')
RuntimeError: Cannot find /home/mkreim/bin/cling-Ubuntu-16.04-x86_64-0.6~dev-3a5d26e/lib/libclingJupyter.{so,dylib,dll}

Like @aisaro , I cannot find the lib via find / -iname "*clingJupyter*" on my system.

But running cling works like expected.

Do you have any ideas what is going wrong here? Thanks a lot.

Axel-Naumann commented 6 years ago

@aisaro - where did you get cling from?

@mkreim - I don't have a lot of experience with cpt.py, @vgvassilev mind helping out? (And why did you decide to do a Debug build - that's really really slow...) An alternative is the good old traditional build, see here: https://root.cern.ch/cling-build-instructions

mkreim commented 6 years ago

@Axel-Naumann : Thanks a lot for your answer and please excuse by delayed answer. There was no reason for doing a Debug build. I simply did not see it (copy & past can be a curse). I retried installing cling using your steps (really much faster and using less resources. Thanks!) and everything went through without any errors:

git clone http://root.cern.ch/git/llvm.git
cd llvm/
git checkout cling-patches
cd tools/
git clone http://root.cern.ch/git/cling.git 
git clone http://root.cern.ch/git/clang.git 
cd clang 
git checkout cling-patches
cd ../../
mkdir build
cd build/
cmake -DCMAKE_INSTALL_PREFIX=~/bin/cling/ -DCMAKE_BUILD_TYPE=Release ../llvm
cmake --build . && cmake --build . --target install
cd ~/bin/cling/share/cling/Jupyter/kernel/
pip install -e .
jupyter kernelspec install cling-cpp11 --user
jupyter kernelspec install cling-cpp14 --user
jupyter kernelspec install cling-cpp17 --user
jupyter kernelspec install cling-cpp1z --user

Again cling works as expected but all four kernels crash immediately after opening a notebook in jupyter (like before). However, this time I could find the needed library ~/bin/cling/lib/libclingJupyter.so

So all I was left to do was adding the library path to my .bashrc:

CLANG_PATH=~/bin/cling/
export LIBRARY_PATH=${CLANG_PATH}/lib/:$LIBRARY_PATH
export CPATH=${CLANG_PATH}/include/:$CPATH
export LD_LIBRARY_PATH=${CLANG_PATH}/lib/:$LD_LIBRARY_PATH

And after a restart of jupyter I can now run silly C++ code:

image

So Thanks a lot, @Axel-Naumann !

Axel-Naumann commented 6 years ago

OK looks like this was settled years ago - let me close it then :-) Please suggest PRs to READMEs and build files as needed to make things more stable!