Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reticulate ImportError: No module named pandas in Rstudio version 1.2

I am trying to use the reticulate package in a Rmd file. I first created a setup chunk as follows:

library(reticulate)
use_virtualenv("r-reticulate")
use_python("C:\\Python27")

Then I import pandas:

#importing libraries
import pandas 
 ImportError: No module named pandas

Detailed traceback: 
  File "<string>", line 1, in <module>  

I have checked that pandas is already installed from the python command line. Why am I getting an import error here?

like image 578
umair durrani Avatar asked Jan 18 '19 21:01

umair durrani


2 Answers

install the package in R using the py_install()

library(reticulate)
py_install("pandas")

refer this -> https://rstudio.github.io/reticulate/articles/python_packages.html

like image 141
Nandan Avatar answered Sep 21 '22 08:09

Nandan


It appears pandas is not installed in your virtualenv. It may be on your machine, but your virtualenv isolates your application from the rest of your machine.

While your virtualenv is active:

  • Open cmd/bash
  • Run pip install pandas

Now pandas should be available to you within this env. Later you can generate a requirements.txt file that makes dependency management much easier.

like image 20
CodeSpent Avatar answered Sep 21 '22 08:09

CodeSpent