我不理解 R 如何处理 Python 环境和 Python 版本,一直收到错误信息 Error: could not find a Python environment for /usr/bin/python
。我在 shell 中安装了 Miniconda 并创建了一个 conda 环境:
conda activate r-reticulate
然后,在 R 中,我尝试安装 keras(使用 tensorflow 包时也出现了同样的问题):
library(keras)
reticulate::use_condaenv()
install_keras(method = "conda", conda = reticulate::conda_binary())
...并收到以下错误:
Error: could not find a Python environment for /usr/bin/python
我试图弄清楚Python R应该使用什么
reticulate::py_config()
并获取
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
我不理解这个。它似乎在使用Python 2.7。当我尝试弄清楚shell中正在使用哪个Python时,我得到了:
> which python
/opt/miniconda3/envs/r-reticulate/bin/python
和
> 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
建议使用Python 3.6。
我在这里错了什么?
conda install tensorflow
(安装v. 2.2.0)和conda install keras
(安装v. 2.4.3)在shell中完成了安装。 - stineb