Reticulate source_python import modules

I am trying to run in R using reticulate. The wrinkle is that imports another script,, which is located in the same directory. If I run in python, import pyscript2 works fine.

However, using reticulate in R, source_python() throws ModuleNotFoundError: No module named 'pyscript2'. If I remove the import from, then no error is thrown with source_python().

I am sure there is something specific I am missing about the reticulate sourcing process, but I am unable to figure out from the documentation or source code what the issue is.

My rscript.R script:

use_condaenv('myenv', required = TRUE)

My script:

import pyscript2

My script:

1 Like

I have the same issue. Were you able to solve this?

also having trouble importing a custom python module for use with reticulate.

In python, local modules can be imported in same manner as any python module. Same with reticulate?

1 Like

I solved the problem with the belt and suspenders approach. Importing then sourcing did the trick, e.g.:

import_from_path("data", path = "./src/data/")

In case you are in rmarkdown and you are having directory problems, e.g. your .rmd files and source files are in different directories, you may need reset the root directory in knitr like:

knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())