首页 > 解决方案 > 错误:无法找到 conda 二进制文件。Anaconda 安装了吗?

问题描述

我正在尝试在 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?**

标签: pythonrpython-3.xanacondaconda

解决方案


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

RETICULATE_PYTHON环境变量

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

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

reticulate.conda_binary选项

reticulate可以选择指定 conda 可执行文件(在此处定义)。你能试试这个吗?

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

PATH环境变量

您还可以尝试PATH在 R 中设置变量以包含您的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

推荐阅读