How to use Python in RStudio

I am trying to run Python in RSTUDIO but unable to do it..

Installed the library reticulate. But when I run Import Pandas as pd getting the below error.

ModuleNotFoundError: No module named 'pandas'

Detailed traceback:
File "", line 1, in

Do you have installed pandas for the python version reticulate is using? (python 2.7 by default )

I don't understand. I am having Python 3.7 version installed and I don't have other IDE. Only RSTUDIO

On what operating system are you? Also even if you only have python 3.7 installed do you have installed pandas? If so, is pandas installed on a virtual environment?

Sorry for delayed reply.

I am using WIN Server 2016 64 bit machine. After installing Python I am not able to install pandas using python due to network issue / network restriction. Hence I thought I can use RSTUDIO as an IDE for Python programming...

I think there is some kind of misunderstanding going on here, you can't import pandas without installing it first, regardless of the IDE you are using.

You can install python packages from R console this way

library(reticulate)
py_install("pandas")

After that you should be able to import pandas module

1 Like

Yes I am looking for the same. I mean first to install then import. Below is the error when I ran the code in R Console.

library(reticulate)
py_install("pandas")
Error: Windows Conda installation failed (no conda binary found)

Install Anaconda 3.x for Windows (https://www.anaconda.com/download/#windows)
before proceeding

How do you have installed python in your system?
You can manually specify the location of the python executable using the reticulate::use_python() function.

I manually installed PYTHON from https://www.python.org/downloads/windows/ but used a custom path C:\Users\John\Python

Moreover I am not using Anaconda. I have installed the default python from python website

Have you tried specifying the custom path to python.exe file? I don't know the exact path but it should look like this

library(reticulate)
use_python(python = "C:\Users\John\Python\python.exe")

Followed the instructions and again got the same message.

library(reticulate)
use_python(python = "C:\Users\kumarv3\Python\python.exe")
Error: '\U' used without hex digits in character string starting ""C:\U"
use_python(python = "C:\Users\kumarv3\Python\python.exe")
py_install("pandas")
Error: Windows Conda installation failed (no conda binary found)

Install Anaconda 3.x for Windows (https://www.anaconda.com/download/#windows)
before proceeding

1 Like

"\U" in your path is being considered as a metacharacter try with scaping with an extra "\", also make sure that the path is correct since you are showing a different path than in your previous post.

library(reticulate)
use_python(python = "C:\\Users\\kumarv3\\Python\\python.exe")
py_install("pandas")

I think to run py_install() on Windows, you have to have conda installed. From ?py_install:

On Linux and OS X the "virtualenv" method will be used by default ("conda" will be used if virtualenv isn't available). On Windows, the "conda" method is always used.

I highly recommend installing Miniconda3 if you are planning on doing data science with Python on Windows. It makes it much easier to install packages with compiled code (e.g. numpy).

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.