0

I am trying to use a Python block in my R markdown document. Below is what I have been trying:


"""{r setup, include=FALSE}
require(reticulate)
use_python("/Users/hyunjindominiquecho/opt/anaconda3", required = T)
"""

"""{python}
# import the necessary python packages
import numpy as np
import pandas as pd
import scipy.stats as st
from rpy2 import robjects
import math
from scipy.optimize import newton
import torch
from pandas import dataframe
from statistics import mean 
"""

but when I try to do this, R studio shows the following error:

Error in system2(command = python, args = paste0("\"", config_script,  : 
  error in running command

How can I resolve this issue? Thank you,

Phil
  • 7,287
  • 3
  • 36
  • 66
chico0913
  • 577
  • 4
  • 10
  • 22

1 Answers1

0

What if you did:

```{python, engine.path = '/Users/hyunjindominiquecho/opt/anaconda3'} 
import sys
print(sys.version)
```

What happens when you only run the first chunk? Do you still get the same error?

Daniel_j_iii
  • 3,041
  • 2
  • 11
  • 27
  • Thank you very much for your comment. I am getting the same error when I run the first chunk. :S – chico0913 Jun 23 '20 at 01:30
  • Have you tried just running the python chunk, the 2nd one without specifying your python engine? – Daniel_j_iii Jun 23 '20 at 01:46
  • Hello, when I run just the first chunk that I described in my original post, R studio shows no error. It's my second chunk that throws an error. When I run the chunk that you suggested in your post above, I get the same error : `Error in system2(command = python, args = paste0("\"", config_script, : error in running command` :S – chico0913 Jun 23 '20 at 01:54
  • when I run the second chunk without specifying my python engine, I still get the same error. – chico0913 Jun 23 '20 at 01:55
  • take a look [https://stackoverflow.com/questions/53365827/making-system2-use-a-specific-version-of-python] looks like you will need to edit your PATH file and possibly your .Rprofile file – Daniel_j_iii Jun 23 '20 at 01:58
  • Hello! Thank you again for your help. After following the instruction from the link that you gave me, the original error disappeared but now it's complaining that there is no module named `rpy2`, even though I installed the Python module under the Python directory that I used for my PATH.... how can I resolve this issue please? :s – chico0913 Jun 23 '20 at 02:19
  • under my Python folder, there are `bin` and `lib` folder, and under the `lib` folder, there is a directory for the Python module `rpy2`, but my R studio doesn't seem to recognize the module.... – chico0913 Jun 23 '20 at 02:20
  • did you run `conda install rpy2` in python to install it? might be worth reinstalling it to see if it works – Daniel_j_iii Jun 23 '20 at 02:32
  • I installed `rpy2` (tried both `pip install rpy2` and `conda install rpy2`) on my terminal. Then, I executed `system2("/Users/hyunjindominiquecho/opt/anaconda3/bin/python3.7", args="-V")` on my R Studio, and I tried running my 2nd python chunk again, but it doesn't seem to recognize the `rpy2` module I installed. I didn't try re-installing the module, I am not sure how to re-install it. I tried installing the module twice without first removing the existing module. – chico0913 Jun 23 '20 at 02:44
  • The error message that I am now getting is : `3.6.10 | packaged by conda-forge | (default, Apr 24 2020, 16:29:39) [GCC Clang 9.0.1 ] ModuleNotFoundError: No module named 'rpy2'` – chico0913 Jun 23 '20 at 03:13