无法将包含 Python 代码的 R-notebook 编织成 PDF

Unable to Knit To PDF the R-notebook containing Python code

我正在 KNIT TO PDF 这个 R 笔记本包含以下 Python 代码:

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.grid(True)
plt.savefig("test.png")
plt.show()

当我选择 Knit To PDF 时,出现这个错误:

This application failed to start because it could not find or load the Qt platform plugin "windows" in "". Reinstalling the application may fix this problem.

On the other hand, when choosing to Knit To PDF a R-notebook that contains only R code, everything works fine.

你能帮我解决这个错误吗?

我在 找到了问题的答案。我把它贴在这里是为了结束这个问题并供未来的访客使用。