pythonrdockerreticulate

Problem with using Python via R's reticulate in Docker container


I create a Docker image based on rocker/shinyversewith the Dockerfile:

# File: Dockerfile
FROM rocker/shiny-verse:4.2.2

RUN echo "apt-get start"
RUN apt-get update && apt-get install -y \
python3 \
python3-pip 

# install R packages
RUN R -e "install.packages('remotes')"
RUN R -e "install.packages('reticulate')"
RUN R -e "install.packages('tidyverse')"

# Install Python packages datetime and zeep
RUN python3 -m pip install datetime zeep

# Set the environment variable to use Python3
ENV RETICULATE_PYTHON /usr/bin/python3

Then I have the simple R file:

library("tidyverse")
library(reticulate)

# Call a simple Python command to calculate 3*5
py_run_string("z = 3+4")
py$z %>% print()

After I launched the container, I want to run this R script with the shell command:

docker exec shiny_new Rscript /home/shiny/ETL/reticulate_test.R

but I get the following error:

Error: Python shared library not found, Python bindings not loaded.
Use reticulate::install_miniconda() if you'd like to install a Miniconda Python environment.
Execution halted

It fails when executing the python

I am unsure how to setup the Python in such a way that I can use python code via reticulate in my R script. Does anybody have an idea where I go wrong in setting up the Docker image?


Solution

  • Folowing this issue, it seems pyenv installs Python without the Python shared library.

    You should try to add:

    or