R中的Python-错误:找不到/usr/bin/python的Python环境 [英] Python in R - Error: could not find a Python environment for /usr/bin/python
问题描述
我不明白R如何处理Python环境和Python版本,并不断收到错误Error: could not find a Python environment for /usr/bin/python
.我安装了Miniconda并在外壳中创建了一个conda环境:
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
然后,在R中,我尝试安装keras(与tensorflow包相同的问题):
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
我试图弄清楚应该使用什么Python R
I tried to figure out what Python R should be using by
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时,我得到:
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
和
> 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.
Suggesting Python 3.6 should be used.
我在这里怎么了?
推荐答案
尝试遵循 https:/上的指南/tensorflow.rstudio.com/installation/:
在您的R-studio控制台中:
In your R-studio console :
-
install.packages(tensorflow)
library(tensorflow)
install_tensorflow()
如果尚未手动安装Anaconda/Miniconda,则在步骤no. 3,提示将询问您的许可以安装Miniconda.如果您已经安装了conda
,则:
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 :
- 在conda中创建新环境
r-reticulate
:conda create -n r-reticulate
- 使用以下参数从R-studio控制台安装tensorflow:
install_tensorflow(method = 'conda', envname = 'r-reticulate')
- 加载网状包
library(reticulate)
- 在R-studio
use_condaenv('r-reticulate')
中激活conda环境.
- 加载tensorflow libray
library(tensorflow)
- 检查tensorflow是否处于活动状态
tf$constant("Hellow Tensorflow")
- Create new environment
r-reticulate
in conda :conda create -n r-reticulate
- Install tensorflow from R-studio console with parameters :
install_tensorflow(method = 'conda', envname = 'r-reticulate')
- Load the reticulate package
library(reticulate)
- Activate the conda environment in R-studio
use_condaenv('r-reticulate')
- Load the tensorflow libray
library(tensorflow)
- Check if tensorflow is active
tf$constant("Hellow Tensorflow")
参考文献:
- https://tensorflow.rstudio.com/installation/
- https://rstudio.github.io/reticulate/
这篇关于R中的Python-错误:找不到/usr/bin/python的Python环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!