Config/reticulate not setting up environment - ModuleNotFoundError: No module named 'pandas'

I am trying to build an R package that wraps an internal python module; however, it seems to not be properly installing the dependencies like I would expect. According to the documentation, I should be able to define the Config/reticulate field in the DESCRIPTION file and it will handle setting up the python environment; however, it doesn't seem that's happening. Reticulate dependency vignette

This is somewhat of a migration project, so currently we're writing R objects to file, then using system(command) to run the python code before reading the results back into R. There are reasons it's done this way, although the plan is to leverage more of the reticulate tools to reduce read/write, I just don't have the time to make those changes right now.

I've replaced system with py_run_file() without success and py_module_available('pandas') returns false after loading the package. If I initialize reticulate in the directory, this resolves the problem, but that doesn't solve my package distribution problem (internal package).

I guess the question is: How do I ensure reticulate::configure_environment() actually runs when distributing a package?

Below is a rough reproduceable example, making the changes to a RStudio new package template should successfully not work.

RunDemoPy <- function(){
  pyScript = system.file("python/", package = "pyTestpkg")


    packages = list(
      list(package = "pandas")


.onLoad <- function(libname, pkgname){
  packageStartupMessage("On Load - config environment")

.onUnload <- function(libname){

.onAttach <- function(libname, pkgname){    


import os
import pandas as pd

pdf = pd.DataFrame()

print("Dataframe done")
1 Like

This topic was automatically closed after 45 days. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.