【问题标题】:Error: Unable to find conda binary. Is Anaconda installed?错误:无法找到 conda 二进制文件。 Anaconda 安装了吗?
【发布时间】:2020-07-13 09:59:54
【问题描述】:

我正在尝试在 R 中运行 python 脚本。我有一个 macOS Catalina 10.15.4 并且我继续收到此错误:

"Error in value[[3L]](cond) : 
  Need to install Anaconda from https://www.anaconda.com/download/.
Error: Unable to find conda binary. Is Anaconda installed?"

我已经下载了python 3.8,也已经下载了anaconda。用尽谷歌搜索后。我正在学习我的 conda 的路径可能是问题所在。谷歌搜索然后建议使用“use_condaenv()”来指定正确的路径,但我仍然收到相同的错误:错误:无法找到 conda 二进制文件。 Anaconda 安装了吗?”

简而言之:如何找到我的二进制 conda 的正确位置?如何准确更正路径?如何解决该错误?

这是我到目前为止运行的语法:

install.packages("reticulate")

library(reticulate)

repl_python()

Python 2.7.16 (/usr/bin/python)

Reticulate 1.13 REPL -- A Python interpreter in 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, Feb 29 2020, 01:55:37)  [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc-
numpy:          /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
numpy_version:  1.8.0

python versions found: 
 /usr/bin/python
 /usr/bin/python3
 /usr/local/bin/python3

use_python("/usr/bin/python3", required = TRUE)

**ERROR: The requested version of Python ('/usr/bin/python3') cannot be used, as another version of
Python ('/usr/bin/python') has already been initialized. Please restart the R session if you need
to attach reticulate to a different version of Python.
Error in use_python("/usr/bin/python3", required = TRUE) : 
  failed to initialize requested version of Python**

Sys.which("python")

           python 
"/usr/bin/python" 

install.packages("youtubecaption")

library(youtubecaption)

**The downloaded binary packages are in
    /var/folders/n2/kl03cmjj04n5msjq8x8mt_yr0000gn/T//RtmpD82WW0/downloaded_packages**

url<-"https://www.youtube.com/watch?v=qATvD6kQ47s&t=339s" #this is just an example url#

caption<-get_caption(url)

**Error in value[[3L]](cond) : 
  Need to install Anaconda from https://www.anaconda.com/download/.
Error: Unable to find conda binary. Is Anaconda installed?**

【问题讨论】:

  • 你安装的是什么版本的 conda? Python 2 还是 Python 3?根据上面的代码,你正在尝试混合使用 python 2 和 3,这肯定是行不通的。
  • 我安装了python 3.8。我试图通过输入来指定:use_python("/usr/bin/python3", required = TRUE) 但它不起作用。

标签: python r python-3.x anaconda conda


【解决方案1】:

您可以尝试以下三种不同的方法。

RETICULATE_PYTHON环境变量

Reticulate 还会搜索环境变量RETICULATE_PYTHON,您可以在其中定义要使用的python。定义here

Sys.setenv(RETICULATE_PYTHON = "path/to/anaconda/bin/python")
library(reticulate)
# and so on

reticulate.conda_binary 选项

reticulate 有一个选项来指定 conda 可执行文件(定义 here)。你可以试试这个吗?

options(reticulate.conda_binary = "path/to/bin/conda")
library(reticulate)

PATH 环境变量

您也可以尝试在 R 中设置 PATH 变量以包含您的 anaconda/bin 目录:

# Prepend the anaconda/bin directory so that python installation 
# is found before any others.
original_path <- Sys.getenv("PATH")
Sys.setenv(PATH = paste("path/to/anaconda/bin", original_path, sep = ":"))

library(reticulate)
reticulate::py_config()
# and so on

【讨论】:

  • 对于基于apple Silicon(M1)的新mac,conda是通过miniforge而不是miniconda安装的,所以conda路径看起来不一样,通常是这样的:~/miniforge3/condabin/conda
猜你喜欢
  • 2019-02-21
  • 1970-01-01
  • 1970-01-01
  • 2018-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-26
  • 2017-05-14
相关资源
最近更新 更多