我已经使用knitr
了很长时间,通常是在R Studio环境中。最近,我在Windows机器上安装了Python(版本3.4.1),将其放入路径中,并试用了Yi Hui Xie的Python示例文档。但是Python代码块不会运行。从这样的块中:
{r test-python, engine='python'}
x = 'hello, python world!'
print x
print x.split(' ')
我收到这样的错误消息:
Warning: running command '"python" -c "print '**Write** _something_ in `Markdown` from `Python`!'"' had status 1
running: "python" -c "x = 'hello, python world!'
print x
print x.split(' ')"
File "<string>", line 2
print x
^
SyntaxError: invalid syntax
我在Windows 7中,运行R 3.1.0,并带有RStudio版本0.98.847(测试版预览版)。从命令行打开Interactive Python就好了。
有任何想法吗?
您的问题是您已经安装了python3,但是使用的语法是python2。py2-> py3过渡涉及到语言本身的更改-在您的示例中,print
已从语法更改为函数。(因此print(x)
可以在上面的代码中使用。)
最简单的选择是卸载python3并安装最新的Python 2.7(当前为Python 2.7.6)。或者,向前和向上–使用py3,它仅涉及可能会调整您在中遇到的任何现有示例knitr
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句