I am trying to run python as rmarkdwon code chunks. I was successful but rmarkdown by default uses Python2 and I want it to use Python 3. I am running it on Ubuntu with Python 2.7.6 installed and I installed anaconda with Python 3.5, which is the one I want rmarkdown use.
Here is the code and output of the python chunk in rmarkdown
import sys
print (sys.version)
and the output:
2.7.6 (default, Jun 22 2015, 17:58:13)
Any ideas?
Overview. The reticulate package includes a Python engine for R Markdown that enables easy interoperability between Python and R chunks. Python chunks behave very similar to R chunks (including graphical output from matplotlib) and the two languages have full access each other's objects.
To add a Python code chunk to an R Markdown document, you can use the chunk header ```{python} , e.g., ```{python} print("Hello Python!") ```
You can select your desired python version, as default, with an R chunk:
```{r setup, echo=FALSE}
library(knitr)
opts_chunk$set(engine.path = '/usr/bin/python3')
```
From now on your python chunks will use Python3:
```{python}
import sys
print(sys.version)
```
This way to select python version avoids to add the engine.path
variable to every code chunk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With