如何指定 rmarkdown 使用 python3 而不是 python 2? [英] How can I specify rmarkdown to use python3 instead python 2?
问题描述
我正在尝试将 python 作为 rmarkdwon 代码块运行.我成功了,但 rmarkdown 默认使用 python2,我希望它使用 python 3.我在安装了 python 2.7.6 的 Ubuntu 上运行它,我用 pytthon 3.5 安装了 anaconda,这是我想要 rmarkdown 使用的那个.下面是rmarkdown中python块的代码和输出
I am trying to run python as rmarkdwon code chunks. I was sucessfull 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 pytthon 3.5, which is the one I want rmarkdown use. Here is the code and output of the python chunk in rmarkdown
```{python}
import sys
print (sys.version)
```
和输出:
2.7.6 (default, Jun 22 2015, 17:58:13)
有什么想法吗?
推荐答案
您可以添加 engine.path = '/path/to/python3'
来覆盖 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)
```
<小时>
这篇关于如何指定 rmarkdown 使用 python3 而不是 python 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!