Problem with python submodule when knitting

This is my first attempt to mix R and Python, and I'm running into problems when I try to knit the .Rmd with the following chunks:

library(reticulate)
reticulate::use_python("/home/XXXXX/.pyenv/shims/python", required=TRUE)
py_discover_config()

architect <- import_from_path("src", path=here(), delay_load = FALSE)
print("ok")
res <- architect$utils$camera_utils$get_camera_param()

get_camera_param imports a bunch of other modules from throughout src.utils which is why I did the import at the src level. If I run the chunks manually in Rstudio, it works fine. But when I try to knit the file I get the following error:

Quitting from lines 51-52 (plot_camera.Rmd)
Error in py_get_attr_impl(x, name, silent) :
AttributeError: module 'src.utils' has no attribute 'camera_utils'
Calls: ... py_get_attr_or_item -> py_get_attr -> py_get_attr_impl
Execution halted

Any ideas/suggestions?

Is this possible to share the underlying code so I can reproduce ?

Does the code works in the Python REPL or at the R console ?

The issue is only with R Markdown ?

Having a reproducible example would help investigate. Thanks !

Yes, I only get the error when I try to knit the .Rmd file. It works if I execute in the R console or if I run the chunk manually.

Unfortunately, I can't share the underlying python code. I'll try to mockup some python modules that mimic the import structure that I can share.

Thank you that will help a lot !

@melissawong Also can you try with the development version reticulate ?

remotes::install_github("rstudio/reticulate")

Thank you.

@cderv , I was able to mock up a minimalist example that recreates the problem. In fact, the mock example now fails with the same error whether I try to run the chunk manually or knit it. What's the best way to get the files to you? I've got a *.tgz file with the entire folder structure, but it doesn't look like I can upload *.tgz or *.tar files here.

Can you share the source files on Github ?

You can use a fileshare service and send me the link in DM otherwise.

Also please try the dev version of reticulate thanks.

In case anyone else runs into this problem, using the here package and setting knitr::opts_knit$set(root.dir=here()) fixed my problem with knitting.