[R] Problem to run python code in r markdown

@vi@e@gross m@iii@g oii gm@ii@com @vi@e@gross m@iii@g oii gm@ii@com
Fri Jan 20 21:33:04 CET 2023


Kai,

Just FYI, this is mainly an R mailing list and although there ware ways to combine python with R (or sort of alone) within environments like RSTUDIO, this may not be an optimal place to discuss this. You are discussing what is no longer really "R markdown" and more just plain "markdown" that supports many languages in many environments and you are using one called flexdashboard.

I had a similar problem for a while because I had an amazing number of copies of python installed on my machine in various ways including directly and within Anaconda and several other ways. Each may have kept copies of modules like numpy in a different place. Unfortunately, when running python from RSTUDIO, it was looking in a place that did not have it and when I used "pip" to get the latest copy, it insisted I already had it!

So I eventually uninstalled all versions I could find and reinstalled just one version and then got the numpy and pandas modules installed under that version. Oh, I also replaced/updated RSTUDIO. Things work fine for now.

Some people may advise you on how to determine which version of python you are calling, or change it, and how to download numpy to the place it is expected, or change some environmental variable to point to it or any number of other solutions. Some like virtual environments, for example.

The bottom line is your setup does not have numpy installed as far as the software is concerned even if it is installed somewhere on your machine. When you get things aligned, you will be fine. 

-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Kai Yang via R-help
Sent: Friday, January 20, 2023 11:20 AM
To: R-help Mailing List <r-help using r-project.org>
Subject: [R] Problem to run python code in r markdown

Hi Team,I'm trying to run python in R markdown (flexdashboard). The code is below:

try Python=============
```{r, include=FALSE, echo=TRUE}library(reticulate)py_install("numpy")
use_condaenv("base")
```
```{python}import numpy as np```

I got error message below:
Error in py_call_impl(callable, dots$args, dots$keywords) :   ModuleNotFoundError: No module named 'numpy'Calls: <Anonymous> ... py_capture_output -> force -> <Anonymous> -> py_call_implIn addition: There were 26 warnings (use warnings() to see them)Execution halted


Based on message, the python can not find numpy package. But I'm sure I installed the package. I don't know how to fix the problem. please help Thank you,Kai















	[[alternative HTML version deleted]]

______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list