Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
  • 1.  Jupyter NB graphviz package

    Posted Mon January 04, 2021 09:13 AM
    I want to import and use the graphviz package in my Notebook so i installed this package with the command !pip install --user graphviz

    When I run the following code an error message appears.Does anyone know how to fix this?

    import graphviz as gvz

    d = gvz.Digraph()
    d.edge('from a','to b')
    d

    Error message:
    FileNotFoundError                         Traceback (most recent call last)
    ~/.local/lib/python3.7/site-packages/graphviz/backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
        163     try:
    --> 164         proc = subprocess.Popen(cmd, startupinfo=get_startupinfo(), **kwargs)
        165     except OSError as e:
    
    /opt/anaconda3/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
        799                                 errread, errwrite,
    --> 800                                 restore_signals, start_new_session)
        801         except:
    
    /opt/anaconda3/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
       1550                             err_msg += ': ' + repr(err_filename)
    -> 1551                     raise child_exception_type(errno_num, err_msg, err_filename)
       1552                 raise child_exception_type(err_msg)
    
    FileNotFoundError: [Errno 2] No such file or directory: 'dot': 'dot'
    
    During handling of the above exception, another exception occurred:
    
    ExecutableNotFound                        Traceback (most recent call last)
    /opt/anaconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
        343             method = get_real_method(obj, self.print_method)
        344             if method is not None:
    --> 345                 return method()
        346             return None
        347         else:
    
    ~/.local/lib/python3.7/site-packages/graphviz/files.py in _repr_svg_(self)
        142 
        143     def _repr_svg_(self):
    --> 144         return self.pipe(format='svg').decode(self._encoding)
        145 
        146     def pipe(self, format=None, renderer=None, formatter=None, quiet=False):
    
    ~/.local/lib/python3.7/site-packages/graphviz/files.py in pipe(self, format, renderer, formatter, quiet)
        169         out = backend.pipe(self._engine, format, data,
        170                            renderer=renderer, formatter=formatter,
    --> 171                            quiet=quiet)
        172 
        173         return out
    
    ~/.local/lib/python3.7/site-packages/graphviz/backend.py in pipe(engine, format, data, renderer, formatter, quiet)
        246     """
        247     cmd, _ = command(engine, format, None, renderer, formatter)
    --> 248     out, _ = run(cmd, input=data, capture_output=True, check=True, quiet=quiet)
        249     return out
        250 
    
    ~/.local/lib/python3.7/site-packages/graphviz/backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
        165     except OSError as e:
        166         if e.errno == errno.ENOENT:
    --> 167             raise ExecutableNotFound(cmd)
        168         else:
        169             raise
    
    ExecutableNotFound: failed to execute ['dot', '-Kdot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH


    ------------------------------
    Bastiaan Krijgsman
    ------------------------------

    #CognosAnalyticswithWatson


  • 2.  RE: Jupyter NB graphviz package

    Posted Tue January 05, 2021 05:23 AM
    Hi Bastiaan,

    we struggle with the same problem. The reason is: GraphViz needs a server-side binary. We do not know how to include the binary into the jupyter notebook server (running on Linux). I think we have to include the binary in the additional_os_packages file and rebuild the image.

    If there is any notebook-specialist around here, please gie us a hint how to include the binaries.

    cheers
    Martin

    ------------------------------
    Martin Otto
    senior solution expert
    avantum consult AG
    Konstanz area
    ------------------------------



  • 3.  RE: Jupyter NB graphviz package

    Posted Tue January 05, 2021 06:41 AM
    Edited by System Admin Fri January 20, 2023 04:40 PM
    I solved this problem by installing the concerning package on the Notebook server in the Jupyter container. The problem is that if you use !pip install graphviz you only install the front end part of the library graphviz

    By adding a line with the value graphviz to the file additional_pip_packages.txt and the file additional_conda_packages.txt you can use the library graphviz with only the import graphviz statement.

    Note, after modifying the mentioned files you have to stop (stop.sh), rebuild (build.sh) and start  (startup.sh) the Docker container. Also in the file additional_conda_packages.txt IBM refers for the wright syntax to a conda topic. This is not wright! You only have to add a line with the name of the package graphviz instead of conda install graphviz

    ------------------------------
    Bastiaan Krijgsman
    ------------------------------



  • 4.  RE: Jupyter NB graphviz package

    Posted Tue January 05, 2021 06:31 AM
    Edited by System Admin Fri January 20, 2023 04:19 PM
    Hi there…

    I am not a python expert but here is how I understand why you get the error and how you can get it working. As Martin indicates, the graphviz python package relies on some executables to do its thing. These executables are not in the docker image used for building the Jupyter Notebook Server container that comes with the Cognos installer… So you will need to add these to the container image yourself (or ask your administrator to do this) and then rebuild and restart the containers.

    Here is one way on how you can establish that.

    Assuming you are running Cognos Notebooks on linux, do following stuff as the linux user that runs Cognos Notebooks (root or…) to make sure the graphviz executables will be installed/available in the Docker containers.

    Go to the dist/scripts subdirectory in the path of your Cognos Notebook installation:
    cd /opt/ibm/cognos/jupyter/dist/scripts​

    Make sure to properly backup the current version of the Dockerfile_server_instance file and then open it with your favorite editor (nano, vim…), etc.:

    cp Dockerfile_server_instance Dockerfile_server_instance.orig
    vi Dockerfile_server_instance​

    In the second "USER root" section (as this needs to be run as root) add the code to install the graphviz executables (with apt-get as we use Ubuntu containers):

    USER root
    
    # load additional os packages
    RUN apt-get update && apt-get install -y graphviz​
    
    Note: if you are already installing other stuff it is best to do this in the same "RUN" line for efficiency when building the container. So for example:
    USER root
    
    # load additional os packages
    RUN apt-get update && apt-get install -y \
        build-essential \
        graphviz \
        libxml2​


    Then you need to rebuild and restart the containers (this might take a few minutes).

    Go to the dist/scripts/unix subdirectory in the path of your Cognos Notebooks installation:

    cd /opt/ibm/cognos/python/dist/scripts/unix

    Stop and remove the running Cognos Notebooks containers by running the stop.sh script:

    ./stop.sh

    (Re)build the containers by running the build.sh script:

    ./build.sh

    Start Cognos Notebooks again by running the startup.sh script:

    ./startup.sh

    Optionally, clean up older Cognos Notebooks relate images that are no longer in use by running the prune.sh script:

    ./prune.sh

    I have attached an example of the Dockerfile_server_instance file. Note that this example also contains some other stuff that might not necessarily work in your configuration.


    ------------------------------
    Herman Nielens
    ------------------------------