-
RStudio doesn't like the Microsoft app installation of python
-
So, install python via Anaconda
-
install the reticulate package
-
Find out the executable python in the system by opening the iPython interpreter from Anaconda, then run the code below:
-
import os
-
import sys
-
os.path.dirname(sys.executable) (this line will produce something like: "C:\Users\GRajeg\anaconda3", which in R/mac needs to be changed into "C:/Users/GRajeg/anaconda3")
-
-
in RStudio, given the available path of python exe from the previous step, run the following: reticulate::use_python("C:/Users/GRajeg/anaconda3")
- If successful, no output is produced
-
Next, provided the previous step is successful, we can list python file in the anaconda3 domain:
list.files("C:/Users/GRajeg/anaconda3", pattern = "python")
# [1] "python.exe" "python.pdb" "python3.dll" "python312.dll" "python312.pdb" "pythonw.exe" "pythonw.pdb"
-
Test the python by:
-
Creating a new python script
-
type in:
print("Hello World")
-
run that python code (similar like executing regular R script); it should produce something like this in the console:
-
> reticulate::repl_python()
Python 3.12.4 (C:/Users/GRajeg/anaconda3/python.exe)
Reticulate 1.38.0 REPL -- A Python interpreter in R.
Enter 'exit' or 'quit' to exit the REPL and return to R.
>>> print("Hello World")
Hello World
>>>