1

与此处此处的帖子类似,当我尝试在新的 RStudio Cloud 项目中安装 TensorFlow 时遇到更多麻烦。我知道我需要在本地设置 Miniconda 和虚拟环境,/cloud/project/以便 Python 依赖项与云项目的副本保持一致。以下安装脚本的早期版本有效。

install.packages(c("keras", "rstudioapi", "tensorflow"))
lines <- c(
  paste0("RETICULATE_CONDA=", file.path(getwd(), "miniconda", "bin", "conda")),
  paste0("RETICULATE_PYTHON=", file.path(getwd(), "miniconda", "bin", "python")),
  paste0("WORKON_HOME=", file.path(getwd(), "virtualenvs"))
)
writeLines(lines, ".Renviron")
rstudioapi::restartSession()
reticulate::install_miniconda("miniconda")
reticulate::virtualenv_create(
  envname = "r-tensorflow",
  python = Sys.getenv("RETICULATE_PYTHON")
)
keras::install_keras(
  method = "virtualenv",
  conda = Sys.getenv("RETICULATE_CONDA"),
  envname = "r-tensorflow"
)

但是当我尝试安装 Python 的 TensorFlow 和 Keras 时,我在 Cloud 上遇到错误:

keras::install_keras(
+   method = "virtualenv",
+   conda = Sys.getenv("RETICULATE_CONDA"),
+   envname = "r-tensorflow"
+ )
Using virtual environment 'r-tensorflow' ...
Collecting tensorflow==2.2.0
  Downloading tensorflow-2.2.0-cp38-cp38-manylinux2010_x86_64.whl (516.3 MB)
Killed
Error: Error installing package(s): 'tensorflow==2.2.0', 'keras', 'tensorflow-hub', 'h5py', 'pyyaml==3.12', 'requests', 'Pillow', 'scipy'

我本地 Ubuntu 机器上的相同脚本似乎成功了,但它忽略了我的本地虚拟环境,即使我设置了WORKON_HOME.

> tensorflow::tf_config()
Installation of TensorFlow not found.

Python environments searched for 'tensorflow' package:
 /home/landau/projects/targets-tutorial/miniconda/bin/python3.8

You can install TensorFlow using the install_tensorflow() function.

使用这种通用方法的示例项目:https ://github.com/wlandau/targets-keras 。

4

0 回答 0