I don't understand how R handles the Python environment and Python version and keep getting the error Error: could not find a Python environment for /usr/bin/python
. I installed Miniconda and created a conda environment in the shell:
conda activate r-reticulate
Then, in R, I try to install keras (same problem with package tensorflow):
library(keras)
reticulate::use_condaenv()
install_keras(method = "conda", conda = reticulate::conda_binary())
... and get the following error:
Error: could not find a Python environment for /usr/bin/python
I tried to figure out what Python R should be using by
reticulate::py_config()
and get
python: /usr/bin/python
libpython: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome: /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version: 2.7.16 (default, Jul 5 2020, 02:24:03) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.21) (-macos10.15-objc-
numpy: /Users/bestocke/Library/Python/2.7/lib/python/site-packages/numpy
numpy_version: 1.16.6
tensorflow: [NOT FOUND]
python versions found:
/usr/bin/python3
/usr/local/bin/python3
/usr/bin/python
I don't understand this. This seems to be using Python 2.7. When trying to figure out which Python is being used in the shell, I get:
> which python
/opt/miniconda3/envs/r-reticulate/bin/python
and
> ls -l /opt/miniconda3/envs/r-reticulate/bin/python
lrwxr-xr-x 1 username wheel 9 Aug 2 15:21 /opt/miniconda3/envs/r-reticulate/bin/python -> python3.6
Suggesting Python 3.6 should be used.
What am I getting wrong here?
Try to follow the guide at https://tensorflow.rstudio.com/installation/:
In your R-studio console :
install.packages("tensorflow")
library(tensorflow)
install_tensorflow()
If you have not installed Anaconda / Miniconda manually, then at step no. 3, a prompt will ask your permission to install Miniconda. If you already have conda
installed, then :
r-reticulate
in conda : conda create -n r-reticulate
install_tensorflow(method = 'conda', envname = 'r-reticulate')
library(reticulate)
use_condaenv('r-reticulate')
library(tensorflow)
tf$constant("Hellow Tensorflow")
References :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With