无法在 `reticulate` 中使用 `pandas` 模块

问题描述

我试图在 R 中使用 keras,当我试图调用 flow_images_from_dataframe() 时发生错误

Error in flow_images_from_dataframe() : 
  Pandas (python module) must be installed in the same environment as Keras.Install it using reticulate::virtualenv_install("pandas",envname = "r-tensorflow") or reticulate::conda_install("pandas",envname = "r-tensorflow") depending on the kind of environment you are using.

我尝试了以下方法

reticulate::py_module_available("pandas")
# FALSE.

# checking that environment is there:
reticulate::virtualenv_list()
# "r-reticulate" "r-tensorflow"

# activate the environment:
use_virtualenv('r-tensorflow')

reticulate::virtualenv_install("pandas",envname = "r-tensorflow")
# ...
# ...
# Installing collected packages: pandas
# Successfully installed pandas-1.1.5

# Trying again:
py_module_available("pandas")
# FALSE

# The issue is specific to pandas,other modules are fine:
reticulate::py_module_available('scipy')
# TRUE

解决方法

我仍然不明白那里的问题是什么以及为什么 virtualenv_install() 没有完成这项工作,但帮助我的解决方案就像

py_install("pandas")