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

Reticulate automatically resets RETICULATE_PYTHON variable #1536

Closed
MauricePasternak opened this issue Feb 9, 2024 · 4 comments
Closed

Reticulate automatically resets RETICULATE_PYTHON variable #1536

MauricePasternak opened this issue Feb 9, 2024 · 4 comments

Comments

@MauricePasternak
Copy link

MauricePasternak commented Feb 9, 2024

System

OS Name: Ubuntu 22.04.03 LTS
RVersion: 4.3.2
IMPORTANT
Also, I use VSCode with the R and R Debugger extensions:
image

And as part of that, I have radian installed as the R terminal when using VSCode.

All instructions here were followed and have worked seamlessly: https://code.visualstudio.com/docs/languages/r

Steps to reproduce:

  1. Create a virtualenv. I used poetry.
>>> poetry new reticulate_bug
Created package reticulate_bug in reticulate_bug
>>> cd reticulate_bug
>>> poetry shell

If it makes any difference, my virtualvenv will have its .venv folder created at the project's root. In this case the reticulate_bug root level folder.

image

  1. Simply check the RETICULATE_PYTHON environment while loading in the library

image

There's no reason for it to do that.

Putting a .Renviron at the root directory does not assist with preventing this either; `reticulate will just overwrite matters even when the library is not explicitly loaded in:

image

@t-kalinowski
Copy link
Member

t-kalinowski commented Feb 9, 2024

Radian uses reticulate under the hood. By the time you're presented with the R repl by radian, reticulate has already selected and initialized a Python installation. If you want to use reticulate from radian with a specific python installation, you have to point radian at the Python you want it to use before the start of the R session. (E.g, set RETICULATE_PYTHON before launching radian, or consult the radian docs for other approaches).

@MauricePasternak
Copy link
Author

Thanks @t-kalinowski

I can confirm that taking the following steps/guidelines makes things workable:

  1. Uninstall radian if it is located in site-packages of any global python interpreter.

  2. Installing radian once a project's/local virtual environment is activated.

  3. For quality-of-life improvement, making a .vscode/settings.json file in that project and putting settings like r.rterm.linux to point to the venv's python binary.

Given the above, once the virtualenv is activated, clicking on the R: (not attached) button will open up a radian terminal in which importing reticulate will point to the appropriate python interpreter.

Fair heads up though, this whole VSCode + radian + reticulate setup doesn't play nice with Quarto's attempts to render a .qmd file into, say, a presentation. Working without radian is recommended there, unfortunately. But that is beyond the scope of this repository. Additionally, it appears it is impossible to have reticulate operate with a jupyter engine, a knitr engine is the only one that will result in bidirectional Python <--> R communication.

Thanks again and cheers!

@t-kalinowski
Copy link
Member

Thank you for the detailed write-up! This should be very useful as other users encounter similar issues.

@ggruenhagen3
Copy link

I enjoy using radian, but it's disappointing that we can't use different python versions on-the-fly with it. I hope this issue is solved in the future!

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