pythonrcondareticulate

What is the easiest way to share a python environment?


So my goal is for a group of biologists to use a python library via the R language, because they only know this language. The library is scSpectra, that is not a really common library. There are some others libraries they need, like pyvis and rpy2.

There's an R library (reticulate) that allows the use of python scripts and libraries. The goal is for the biologists to install a python environment on their computer, and then use reticulate in R to call the scSpectra library.

I have issues with the installation of scSpectra on my computer, so I think that asking the biologists to install the libraries will not go well.

So what is the best way to easily share a python environment ?

I tried creating a python venv, but that's where things got wrong. Installing with pip rpy2 and pyvis gone well, but when I try to install scSpectra, something goes wrong whith the installation of numpy (scSpectra needs a specific range of versions). I didn't find how to solve the issue.

I then tried creating a conda environment, but I still got issues with downloading numpy, that I manage to solve this time. I don't know if I can share this environment in any way...

My last guess is to use docker, but I've never used it, so I don't know if it can be compatible with the "reticulate" R library.


Solution

  • Use conda to install common bioinformatics (and many other) packages. For example, create a separate conda environment with a specific name (here, scspectra_plus), and install into this environment your libraries of choice using conda channels as listed in the order prioritized as listed from left to right (e.g., conda-forge prioritized above bioconda). This command needs to be executed once, to install the packages:

    conda create -n scspectra_plus numpy scanpy scipy pandas matplotlib scSpectra anndata seaborn h5py -c conda-forge -c bioconda -c defaults
    

    Activate this environment like so:

    conda activate scspectra_plus
    

    You can now use the libraries you installed into this environment. For example:

    python -c 'import Spectra; print("ok")'
    

    And deactivate this environment like so:

    conda deactivate
    

    Note: Several libraries (json, glob, math, re, statistics, typing) are parts of the Python standard library, and do not need to be installed.