简体   繁体   English

使用 Reticulate 从 R 导入 Python package(熊猫)

[英]Importing Python package (pandas) from R with Reticulate

Context: I was using Python on Atom IDE and installing/importing packages is working normally.上下文:我在 Atom IDE 上使用 Python 并且安装/导入包工作正常。 Now I would like to work with Python on Rstudio through Reticulate package.现在我想通过 Reticulate package 在 Rstudio 上与 Python 合作。

Problem: I'm not able to import Pandas on Rstudio even though a can Import numpy and math.问题:我无法在 Rstudio 上导入 Pandas,尽管可以导入 numpy 和数学。 The error is "ModuleNotFoundError: No module named 'pandas'".错误是“ModuleNotFoundError:没有名为‘pandas’的模块”。

i) Python 3.8.5 installed (32 bit) ii) pip3 21.1.2 installed iii) Reticulate 1.2.0 installed iv) Pandas is already installed (~\AppData\Local\Programs\Python\Python38-32\Lib\site-packages) i) Python 3.8.5 已安装(32 位) ii) 已安装 pip3 21.1.2 iii) 已安装 Reticulate 1.2.0 iv) Pandas 已安装(~\AppData\Local\Programs\Python\Python38-32\Lib\site-包)

What does your code block look like for instantiating reticulate?用于实例化网状结构的代码块是什么样的?

Here is mine;这是我的; you should get into the habit of using environments as they will ensure all your packages are there and exactly the version you want.你应该养成使用环境的习惯,因为它们将确保你所有的包都在那里,并且正是你想要的版本。

# load python
library(reticulate)
use_python('C:/Users/Andrew/Anaconda3/')
use_condaenv(condaenv='my_ml', required=TRUE)
library(knitr)

You could have many Python environments.您可以拥有许多 Python 环境。

Check reticulate::py_module_available("pandas") .检查reticulate::py_module_available("pandas")

And, if neccesary, reticulate::py_install("pandas") .并且,如果需要,请使用reticulate::py_install("pandas")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM