[英]R reticulate package and python sub-modules
When trying to mimic some python code using R's reticulate package: 当尝试使用R的网状包装模仿某些python代码时:
import_from_path("jwt_auth", "C:/Program Files/Python 3.5/Lib/site-packages/boxsdk/auth")
I get this error: 我收到此错误:
Error in py_module_import(module, convert = convert) :
SystemError: Parent module '' not loaded, cannot perform relative import
Detailed traceback:
File "C:\Program Files\Python 3.5\Lib\site-packages\boxsdk\auth\jwt_auth.py", line 13, in <module>
from .oauth2 import OAuth2
Is there a better way to load sub-modules in R like such: 是否有更好的方式在R中加载子模块,例如:
from boxsdk import JWTAuth
I haven't seen any solid solution. 我还没有任何可靠的解决方案。 In the package I do something like this.
在包装中,我做这样的事情。 Interestingly the drill down of
reportlab
can be done with dot notation. 有趣的是,可以使用点表示法对
reportlab
进行深入研究。
# this is needed in case we use python in the R code rather than source_python
fitz <- NULL
pdfr <- NULL
pdfw <- NULL
repl <- NULL
.onLoad <- function(libname, pkgname) {
# this will fail in package check
reticulate::use_condaenv(condaenv = "myenv", required = TRUE)
fitz <<- reticulate::import("fitz", delay_load = TRUE)
pdfr_0 <- reticulate::import("PyPDF2", delay_load = TRUE)
pdfr <<- pdfr_0$PdfFileReader
pdfw <<- pdfr_0$PdfFileWriter
repl <- reticulate::import("reportlab.pdfgen.canvas", delay_load = TRUE)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.