我正在使用Rmarkdown
通过Rstudio
生成 PDF 文档tex
。在 markdown 中,我编写了python
代码块以实现可重复性。但是,我收到以下错误。
Quitting from lines 23-30 (A4.4.Rmd)
Error in py_call_impl(callable, dots$args, dots$keywords) :
ModuleNotFoundError: No module named 'sklearn'
Detailed traceback:
File "<string>", line 1, in <module>
File "C:\Users\User\Documents\R\win-library\4.0\reticulate\python\rpytools\loader.py", line 24, in _import_hook
level=level
Calls: <Anonymous> ... py_capture_output -> force -> <Anonymous> -> py_call_impl
In addition: Warning message:
In has_crop_tools() :
Tool(s) not installed or not in PATH: ghostcript
-> As a result, figure cropping will be disabled.
Execution halted
它可以编译并生成 PDF,当以代码块形式编写时,R
绝对没有问题。我使用该Reticulate
包来Rstudio
编译Python
代码块。
只有在我转换为 PDF 时才会knit
出现此错误。任何帮助都会有帮助。
答案1
python
是的,我找到了问题所在。我的代码块中缺少的是knitr
设置块。
{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE, engine.path = list(python = 'C:/Users/User/AppData/Local/Programs/Python/Python39/python.exe'))