plasmabio / tljh-repo2docker

Plugin for The Littlest JupyterHub to build multiple user environments with repo2docker
BSD 3-Clause "New" or "Revised" License
60 stars 15 forks source link

Ability to install packages with conda #39

Open pierrepo opened 4 years ago

pierrepo commented 4 years ago

Binder allows installation of additional packages within the actual environement by exposing the conda binary and the related base environment. For instance:

! conda info

leads to

     active environment : notebook
    active env location : /srv/conda/envs/notebook
            shell level : 1
       user config file : /home/jovyan/.condarc
 populated config files : /srv/conda/.condarc
          conda version : 4.8.2
    conda-build version : not installed
         python version : 3.7.6.final.0
       virtual packages : __glibc=2.27
       base environment : /srv/conda  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /srv/conda/pkgs
                          /home/jovyan/.conda/pkgs
       envs directories : /srv/conda/envs
                          /home/jovyan/.conda/envs
               platform : linux-64
             user-agent : conda/4.8.2 requests/2.22.0 CPython/3.7.6 Linux/4.19.112+ ubuntu/18.04.5 glibc/2.27
                UID:GID : 1000:0
             netrc file : None
           offline mode : False

This is very convenient to install extra package we might have forgot (albeit not a very good practice :thinking:):

! conda install -c rdkit rdkit -y

With tljh-repo2docker, it seems that the conda binary is not accessible:

! conda info

leads to

/bin/sh: 1: conda: not found

indeed, conda binary is in /srv/conda/bin/ that is not is PATH:

/srv/home/ppoulain/.local/bin:/srv/conda/envs/notebook/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

However, it also appears that the base conda environment is not writable to the current user:

! /srv/conda/bin/conda info

gives

     active environment : notebook
    active env location : /srv/conda/envs/notebook
            shell level : 1
       user config file : /srv/home/ppoulain/.condarc
 populated config files : /srv/conda/.condarc
          conda version : 4.8.2
    conda-build version : not installed
         python version : 3.7.6.final.0
       virtual packages : __glibc=2.27
       base environment : /srv/conda  (read only)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /srv/conda/pkgs
                          /srv/home/ppoulain/.conda/pkgs
       envs directories : /srv/home/ppoulain/.conda/envs
                          /srv/conda/envs
               platform : linux-64
             user-agent : conda/4.8.2 requests/2.22.0 CPython/3.7.6 Linux/5.4.0-45-generic ubuntu/18.04.5 glibc/2.27
                UID:GID : 1004:1004
             netrc file : None
           offline mode : False

Would it be possible to make the conda bin directory available in PATH and the base environment writable?

jtpio commented 4 years ago

@pierrepo that is when using Plasma, but not with tljh-repo2docker alone?

If so it might be related to how the PATH is set up with the entrypoint:

https://github.com/plasmabio/plasma/blob/7883a6a1266b69ab49f353bdf9974be408bf0709/tljh-plasma/tljh_plasma/entrypoint/entrypoint.sh

pierrepo commented 4 years ago

Oups I raise the issue in the wrong repo @jtpio Do you know how to move an issue to another repo (Plasma's one)?

pierrepo commented 4 years ago

If so it might be related to how the PATH is set up with the entrypoint: https://github.com/plasmabio/plasma/blob/7883a6a1266b69ab49f353bdf9974be408bf0709/tljh-plasma/tljh_plasma/entrypoint/entrypoint.sh

Thanks! I guess the following extra lines should do the trick:

export PATH=${PATH//"/srv/conda/envs/notebook/bin"/"/srv/conda/envs/notebook/bin:/srv/conda/condabin:/srv/conda/bin:/srv/npm/bin"}
chown -R ${NB_USER}:${NB_USER} /srv/conda