reticulate doesn't find python (using steps in the documentation)

Created on 8 Nov 2019  路  5Comments  路  Source: rstudio/reticulate

I have tried multiple ways to install and use reticulate. I believe the README instructions are wrong. I'm using the latest version of reticulate on CRAN. To keep a clean environment, I've been trying to install and use it inside a docker container first.

docker run -it ubuntu

apt-get update && apt-get upgrade -y
apt-get install -y r-base python3
R
> install.packages("reticulate")
> library(reticulate)
> use_python("/usr/bin/python3", required=T)
> os <- import("os")
Error in initialize_python(required_module, use_environment) :
  Python shared library not found, Python bindings not loaded.

Is there something I'm missing? I've seen references to building python from source and passing a shared flag. Does this mean people must build python from source to use reticulate or will reticulate work with standard python binaries installed by linux package managers?

Most helpful comment

I figured out the problem after finding this issue. python3-dev was needed. A full working installation of reticulate is the following:

docker run -it ubuntu

> apt-get update && apt-get upgrade -y
> apt-get install -y r-base python3 python3-dev python3-pip python3-venv
> R
> install.packages("reticulate")
> library(reticulate)
> reticulate::py_discover_config()
python:         /usr/bin/python3
libpython:      /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so
pythonhome:     /usr:/usr
version:        3.6.8 (default, Oct  7 2019, 12:59:55)  [GCC 8.3.0]
numpy:           [NOT FOUND]
> py_install("pandas") # install another python package as a test
> pandas <- import("pandas")

All 5 comments

Hi,

no, there is absolutely no need to compile Python from source. Can you try - in a fresh R session - what is returned by

reticulate::py_discover_config()
Error in initialize_python(required_module, use_environment) :
  Python shared library not found, Python bindings not loaded.

This seems to imply that you have a version of Python installed that was not compiled with a shared library. It seems reticulate is discovering and preferring that Python installation, but is unable to load it.

Can you try - in a fresh R session - what is returned by

reticulate::py_discover_config()

When I run the following order of commands inside a docker container, I get the same error message:

docker run -it ubuntu

> apt-get update && apt-get upgrade -y
> apt-get install -y r-base python3
> R
> install.packages("reticulate")
> library(reticulate)
> reticulate::py_discover_config()
python:         /usr/bin/python3
libpython:      [NOT FOUND]
pythonhome:     /usr:/usr
version:        3.6.8 (default, Oct  7 2019, 12:59:55)  [GCC 8.3.0]
numpy:           [NOT FOUND]
> os <- import("os")
Error in initialize_python(required_module, use_environment) :
  Python shared library not found, Python bindings not loaded.
> quit() # restart R session
> R
> library(reticulate)
> reticulate::py_discover_config()
python:         /usr/bin/python3
libpython:      [NOT FOUND]
pythonhome:     /usr:/usr
version:        3.6.8 (default, Oct  7 2019, 12:59:55)  [GCC 8.3.0]
numpy:           [NOT FOUND]
> os <- import("os")
Error in initialize_python(required_module, use_environment) :
  Python shared library not found, Python bindings not loaded.

I figured out the problem after finding this issue. python3-dev was needed. A full working installation of reticulate is the following:

docker run -it ubuntu

> apt-get update && apt-get upgrade -y
> apt-get install -y r-base python3 python3-dev python3-pip python3-venv
> R
> install.packages("reticulate")
> library(reticulate)
> reticulate::py_discover_config()
python:         /usr/bin/python3
libpython:      /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so
pythonhome:     /usr:/usr
version:        3.6.8 (default, Oct  7 2019, 12:59:55)  [GCC 8.3.0]
numpy:           [NOT FOUND]
> py_install("pandas") # install another python package as a test
> pandas <- import("pandas")

I found I needed pip3 install numpy in stack

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sahil-kumar picture sahil-kumar  路  9Comments

herboratory picture herboratory  路  6Comments

VyshaliEnukonda picture VyshaliEnukonda  路  8Comments

ruthkr picture ruthkr  路  5Comments

dougmet picture dougmet  路  6Comments