Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with reticulate executing a Quarto file #1499

Open
JulianRamajo opened this issue Oct 25, 2023 · 2 comments
Open

Problems with reticulate executing a Quarto file #1499

JulianRamajo opened this issue Oct 25, 2023 · 2 comments

Comments

@JulianRamajo
Copy link

I try to execute the following qmd file:


title: "Prueba"
author: "JRH"
format: html
editor: visual

R

library(tidyverse)
library(GGally)
library(modelsummary)
library(skimr)

Python

import numpy as np
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt

I receive the following error message:

processing file: Sin-título.rmarkdown
|.......................................... | 80% [unnamed-chunk-2]
Quitting from lines 22-27 [unnamed-chunk-2] (Sin-título.rmarkdown)
Error in py_call_impl():
! ModuleNotFoundError: No module named 'statsmodels'
Run reticulate::py_last_error() for details.
Backtrace:

  1. global .main()
  2. execute(...)
  3. rmarkdown::render(...)
  4. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  5. knitr:::process_file(text, output)
    ...
  6. knitr (local) engine(options)
  7. reticulate::eng_python(options)
  8. reticulate:::py_compile_eval(snippet, compile_mode)
  9. builtins$eval(compiled, globals, locals)
  10. reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)

Execution halted

But individually, in R and Python (repl_python) both scripts function.

@t-kalinowski
Copy link
Member

If a module is importable when working interactively in the console but not when kintting a document, then the most likely reason is that a different python installation is being selected in the different context. The most likely reason for that is that the working directory changes when knitting, and then any configuration that depends on files in the current working directory ( .Rprofile, .Renviron, ./venv, etc.), no longer applies. In that case you will need to apply the appropriate config from another directory, e.g. with readRenviron() or source() or use_virtualenv(here::here("venv"))

@muhammad1imran
Copy link

When press render in R studio I Face this error

processing file: Quarto.qmd
|.......................................... | 80% [unnamed-chunk-2]
Quitting from lines 27-28 [unnamed-chunk-2] (Quarto.qmd)
Error:
! object 'ghs2' not found
Backtrace:

  1. utils::head(ghs2)

Execution halted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants