Search code examples
linuxtensorflowsegmentation-faultsudoubuntu-20.04

segmentation fault with nano editor in command line with ubuntu 20.04


I have Ubuntu 20.04. My command line text editors such as nano or pico can no longer run as a user in the command line, I get

user@hostname:~$ nano 
Segmentation fault (core dumped)

However, things work when I do it with sudo sudo nano, sudo pico etc... I do not have this problem with vi

Since last time it worked, I made the routine updates from Ubuntu, and installed a couple virtual environments with conda. I also edited my LD_LIBRARY_PATH for tensorflow running with CUDA toolkit:

echo $LD_LIBRARY_PATH:

/usr/local/cuda-11.5/lib64:/usr/local/cuda/extras/CUPTI/lib64:/home/rattie/miniconda3/lib/

[UPDATE] It looks like this LD_LIBRARY_PATH edited for tensorflow is the culprit. I was editing it in the conda base environment, instead of isolating that change in a virtual environment created for using tensorflow (e.g. via $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh) In particular, removing /home/rattie/miniconda3/lib/ fixed the issue, although I do not understand why it was causing my commands such as nano to require sudo privileges.


Solution

  • I think your problem come from a library conflict or incompatibility issue, you should set LD_LIBRARY_PATH only for the specific virtual environments that require it like TensorFlow or CUDA.

    lets do an environment activation script in the virtual environment for that:

    first lets create a new directory mkdir -p $CONDA_PREFIX/etc/conda/activate.d then we create a file env_vars.sh touch $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh and add this inside:

    #!/bin/sh
    export OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=/usr/local/cuda-11.5/lib64:/usr/local/cuda/extras/CUPTI/lib64:/home/rattie/miniconda3/lib/:$LD_LIBRARY_PATH
    

    then save and we will create a deactivation script to restore the original LD_LIBRARY_PATH

    mkdir -p $CONDA_PREFIX/etc/conda/deactivate.d 
    

    then we create a file env_vars.sh in it touch $CONDA_PREFIX/etc/conda/deactivate.d/env_vars.sh

    open it and add:

    #!/bin/sh
    export LD_LIBRARY_PATH=$OLD_LD_LIBRARY_PATH
    unset OLD_LD_LIBRARY_PATH
    

    Save and try again, the conflict error should be solved