无法通过 conda、virtualenv 或 py_install 安装带有 reticulate 的 tensorflow

Can't install tensorflow with reticulate via conda, virtualenv, or py_install

提问人:Hack-R 提问时间:11/16/2021 最后编辑:Hack-R 更新时间:11/16/2021 访问量:924

问:

我在尝试使用 .如果我在 CLI 上运行普通 R 会话或普通 Python 会话,我就可以安装和使用 tensorflow。reticulatetensorflow

library(reticulate)                         # loads fine
conda_create("r-reticulate")                # seems to work
conda_install("r-reticulate", "scipy")      # seems to work
conda_install("r-reticulate", "tensorflow") # fails
# Collecting package metadata (current_repodata.json): ...working... done
# Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
# Solving environment: ...working... failed with repodata from current_repodata.json, will retry with next repodata source.
# 
# ResolvePackageNotFound: 
#   - python=3.1
# 
# Error: one or more Python packages failed to install [error code 1]

不知道这是怎么回事,所以我试试了

use_condaenv("r-reticulate")                # seems to work 
py_install("tensorflow")                    # fails

这给出了错误:

错误:找不到 Python 环境 /opt/local/bin/python3.9

所以后来我尝试了:

virtualenv_create("rstudio-python-virtualenv")

引发错误

错误:清理 numpy 的构建目录失败

尽管失败了,但我只是为了笑

virtualenv_install("rstudio-python-virtualenv", "tensorflow") 

这抛出

错误:找不到满足要求的版本 TensorFlow(来自版本:无)

经过一些故障排除后,我尝试将“全局选项”中指定的 Python 解释器更改为上面创建的这 2 个新虚拟环境。它对错误消息没有影响。

我还尝试了哪些投掷:reticulate::py_install("tensorflow")

Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
Solving environment: ...working... failed with repodata from current_repodata.json, will retry with next repodata source.

ResolvePackageNotFound: 
  - python=3.1

Error: one or more Python packages failed to install [error code 1]
>
Python R TensorFlow virtualenv 网状结构

评论

0赞 bricx 11/16/2021
我曾经在使用 conda 时遇到很多麻烦,您是否尝试过使用普通的全新 python 安装,并将其设置为网状结构的默认环境?
0赞 Hack-R 11/16/2021
@bricx很有趣。好吧,我已经尝试了我的系统上已经安装的 Python 3.7 和 3.9,然后我进行了一次全新的 conda 安装,它安装了 3.10。根据我所看到的依赖项冲突,看起来 3.10 对于 tensorflow 的 conda 版本来说可能太新了,所以我将尝试使用 3.6。

答:

1赞 Hack-R 11/16/2021 #1

至少部分问题在于,基于Python版本创建环境,而这些版本对于它试图安装的版本(即Python v3.10.0)来说太新了。这奏效了:conda_createtensorflow

conda_create("r-py-conda-3.6", python_version = "3.6")
conda_install(envname = "r-py-conda-3.6", 
              packages=("tensorflow"))

评论

1赞 richelbilderbeek 11/17/2021
我也有同样的问题,这就是解决它的答案。谢谢@Hack-R!