R中的Python-错误:找不到/usr/bin/python的Python环境 [英] Python in R - Error: could not find a Python environment for /usr/bin/python

查看:949
本文介绍了R中的Python-错误:找不到/usr/bin/python的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 :

  1. 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 :

  1. 在conda中创建新环境r-reticulate:conda create -n r-reticulate
  2. 使用以下参数从R-studio控制台安装tensorflow:install_tensorflow(method = 'conda', envname = 'r-reticulate')
  3. 加载网状包library(reticulate)
  4. 在R-studio use_condaenv('r-reticulate')
  5. 中激活conda环境.
  6. 加载tensorflow libray library(tensorflow)
  7. 检查tensorflow是否处于活动状态tf$constant("Hellow Tensorflow")
  1. Create new environment r-reticulate in conda : conda create -n r-reticulate
  2. Install tensorflow from R-studio console with parameters : install_tensorflow(method = 'conda', envname = 'r-reticulate')
  3. Load the reticulate package library(reticulate)
  4. Activate the conda environment in R-studio use_condaenv('r-reticulate')
  5. Load the tensorflow libray library(tensorflow)
  6. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆