这可能是由于使用低于1.2的RStudio版本造成的。它很好地隐藏在
reticulate
页面,但实际上导入Python包和运行Python块的某些方面似乎是
仅在RStudio 1.2及更高版本中受支持
也就是说,不是当前的RStudio稳定版,而是需要单独下载和安装的预览版。
Here's what they write
在小插曲中:
请注意
RStudio v1.2 preview release
RStudio IDE Tools for reticulate
文章了解更多详细信息。
可能正因为如此,在RStudio 1.1.53中运行代码时,我会像您一样出现“ModuleNotFound”错误,它们会阻止编织。
在RStudio 1.2.1139预览版中运行它时,一切应该是:
Reticulate 1.10 REPL -- A Python interpreter in R.
>>> a=1
>>> a
1
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>>
>>> ## evenly sampled time at 200ms intervals
>>> t = np.arange(0., 5., 0.2)
>>>
>>> ## red dashes, blue squares and green triangles
>>> plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
[<matplotlib.lines.Line2D object at 0x000000001C2EDBE0>, <matplotlib.lines.Line2D object at 0x000000001DA99978>, <matplotlib.lines.Line2D object at 0x000000001DA99D30>]
>>> plt.show()
>>> plt.savefig("test.png")
>>>