擅长:python、mysql、java
<p>我刚找到一个解决办法:</p>
<p>将块用作:</p>
<pre><code><<engine='python', engine.path='python3'>>=
# python code
@
</code></pre>
<ul>
<li>默认情况下,<code>engine.path</code>使用<code>python</code>可执行文件,在大多数Linux系统中,它仍然是<code>python2</code>。如果您想要Python 2,可以使用commit。</li>
<li>如果要输出命令代码,请不要忘记传递<code>echo=FALSE</code>,并且<code>results='asis'</code>,这样它就不会试图转义输出。</li>
</ul>
<p>您可以在文档的开头使用以下块设置默认值:</p>
<pre><code><<r setup, include=FALSE>>=
knitr::opts_chunk$set(echo=FALSE, engine='whathaveyou', ...)
@
</code></pre>
<p>将文件另存为markdown.Rmd,并使用R和knitr编译它。它将使用Python运行Python代码。</p>
<p>R命令:<code>rmarkdown::render('markdown.Rmd','output.html')</code></p>
<p>或者只使用<a href="https://www.rstudio.com/" rel="nofollow noreferrer">RStudio</a>。</p>
<p><strong>附录:</strong>本机解决方案显然是<a href="http://mpastell.com/pweave/" rel="nofollow noreferrer">Pweave</a>:它与乳胶和标记一起工作。不过,我还没有试过。</p>