Installation of keras fails with Error: could not find a Python environment for /usr/bin/python3

Viewed 1082

Software Information:

SUSE Linux Enterprise Server 12 (x86_64) VERSION = 12 PATCHLEVEL = 5

Symbolic link

/usr/bin/python3 --version returns the below; Python 3.4.10

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"

I run the below commands to install keras in the R console.

install.packages("reticulate")

install.packages("tensorflow")

install.packages("tfruns")

install.packages("magrittr")

install.packages("zeallot")

install.packages("R6")

install.packages("generics")

packageurl<-"https://cran.r-project.org/src/contrib/Archive/keras/keras_2.2.4.tar.gz"

install.packages(packageurl,repos=NULL,type="source")

library(keras)

install_keras(tensorflow = "1.9")

In the last step, I get the below error.

Error: could not find a Python environment for /usr/bin/python3

Any help is appreciated here.

Thanks in advance, Venkatesh

2 Answers

I am using an Arch Linux system with R (version 4.1.1). Assuming you have installed Anaconda in your system and is recognized in your path, after you have already installed the reticulate package:

  1. Load the reticulate package: library(reticulate)
  2. Specify the alternate python version to be used: use_python("/usr/local/bin/python")
  3. Specify the environment: use_virtualenv("myenv")
  4. Now install tensorflow:install.packages('tensorflow') then finally install_tensorflow(method = 'conda', envname = 'r-reticulate')

Python 3.4 is not supported by tensorflow, you need minimum 3.6. Additionally, R/reticulate will avoid making changes to a system python installation (anything under /usr/ or /usr/local).

In R, the reticulate package can configure the python environment for you if that makes things easier:

install.packages("keras")

# this will configure a python environment for R 
reticulate::install_miniconda() 

# this will install into the environment configured by reticulate
keras::install_keras() 
Related