positron icon indicating copy to clipboard operation
positron copied to clipboard

Run python code in .qmd file should be able to select interpreter

Open ntluong95 opened this issue 1 year ago • 1 comments

Currently, it is very confusing for users when they mixed R and Python code in a single .qmd file. If only python code chunk, it will run in the system interpreter image

If mixed with R code, it trigger the reticulate environment image

As I don't want to use reticulate, but I want to still mix R and Python code, I found no way to do it. I even toggle off the setting "Use reticulate when run Python code chunk" but it doesn't help, which created a lot of confusions

ntluong95 avatar Jul 03 '24 07:07 ntluong95

If you want to mix R and Python code in the same Quarto document, unfortunately you do have to use the knitr engine and reticulate. This is a limitation of Quarto and not related to Positron; if you use a Jupyter engine, the mapping is "one engine per document" while knitr can handle Python via reticulate.

If you are looking for some best practices for using Python envs from R, I like this blog post by Emil Hvitfeldt: https://emilhvitfeldt.com/post/pyenv-for-r-packages/

It is written from the perspective of an R package developer but the same best practices can be applied to writing documents that mix R and Python. I do this a fair amount and I usually create a project-specific virtualenv that lives in the same directory as my mixed R-and-Python document.

juliasilge avatar Jul 03 '24 18:07 juliasilge

Let us know if you have followup questions about using Quarto with multiple languages!

juliasilge avatar Jul 08 '24 21:07 juliasilge