【问题标题】:install tensorflow in r and run it in python在 r 中安装 tensorflow 并在 python 中运行
【发布时间】:2018-05-25 17:05:25
【问题描述】:

我想知道是否有办法在 R 中安装 tensorflow,然后在 python 中运行此安装。我可以使用指令here 在 R 中成功安装 tensorflow。我还在那个链接上运行了测试,它工作正常。 但是当我打开 Python 并运行 import tensorflow 时,我得到了错误:ImportError: No module named 'tensorflow'。这是一种让 Python 识别来自 R 的安装的方法吗?或者是从 Python 运行 tensorflow 以按照here 的指示安装它的唯一方法? 我想这样做的原因是我和我的同事在我们没有管理权限的机器上工作,我正在尝试生成对每个人都有效的代码。感谢您提出的任何建议。

【问题讨论】:

  • 你可以尝试从 R 调用 Python "system('python test.py hello world', wait = FALSE)"

标签: python r tensorflow


【解决方案1】:

当您加载tensorflow 或在reticulate 上运行的任何其他内容时,会创建(或仅指定)Python 环境,由用户或包的默认设置。如果我没记错的话,tensorflow 的默认值就是r-tensorflow

library(tensorflow)

# check with this, I used a different env name,
use_condaenv("r-tensorflow", required = TRUE)
#> Error in use_condaenv("r-tensorflow", required = TRUE): Unable to locate conda environment 'r-tensorflow'.

# If that's not it, you can check what environments are available
reticulate::conda_list()$name
#> [1] "ANACON~1"       "lime"           "r-planet"       "r-reticulate"  
#> [5] "r-tfgpu"        "spacy_condaenv"

一旦您知道将它安装在哪个 Python 环境中,请激活该环境以直接从 Python 中使用它...例如:从 Anaconda 提示符运行 activate r-tensorflow

【讨论】:

  • 谢谢,但我仍然无法正常运行。 r-tensorflow 是正确的环境,但是当我在 Anaconda Prompt 中运行 activate r-tensorflow 时,尝试在 Python 中运行 import tensorflow 后出现此错误:ImportError: Could not find 'cudart64_90.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 9.0 from this URL: https://developer.nvidia.com/cuda-toolkit
猜你喜欢
  • 2017-04-24
  • 1970-01-01
  • 2017-12-26
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 2021-09-05
  • 2017-09-05
相关资源
最近更新 更多