How can I specify rmarkdown to use python3 instead python 2?
You can add engine.path = '/path/to/python3'
to override the python (2) executable. For example,
---
title: "python"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{python}
import sys
print(sys.version)
```
```{python, engine.path = '/usr/bin/python3'}
import sys
print(sys.version)
```
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.