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

install_tensorflow() - incompatible defaults #586

Closed
astamm opened this issue Oct 19, 2023 · 6 comments
Closed

install_tensorflow() - incompatible defaults #586

astamm opened this issue Oct 19, 2023 · 6 comments

Comments

@astamm
Copy link

astamm commented Oct 19, 2023

IIUC, the first time one wants to use R {tensorflow}, he is expected to run once install_tensorflow() which installs Python {tensorflow} in virtual environment r-tensorflow.

However, by default, the tf version is 2.14 (latest) which runs on Python 3.9-3.11 and the default python version is 3.12, hence resulting in tensorflow not being found (either via pip or via conda-forge).

I am running macOS Ventura 13.6, M1 ARM64, but I believe it is not an OS issue. I believe install_tensorflow() should default to using Python 3.11.

@t-kalinowski
Copy link
Member

t-kalinowski commented Oct 19, 2023

Hi, thanks for raising the issue.

Python version "3.12" just came out earlier this month, so this is a new issue.

That said, install_tensorflow() already has logic that will constrain the python version, and select the oldest suitable version installed on the machine. E.g., if you have called

lapply(sprintf("%s:latest", c("3.8", "3.9", "3.10", "3.11", "3.12")), 
       reticulate::install_python))

And then:

tensorflow::install_tensorflow()

Then the r-tensorflow venv should be created with Python version 3.9.
You can also directly specify the python version desired via

tensorflow::install_tensorflow(python_version = "3.9")

Or:

tensorflow::install_tensorflow(python_version = ">=3.9,<=3.11")

Or:

tensorflow::install_tensorflow(python_version = "3.9,3.10,3.11")

Or even:

tensorflow::install_tensorflow(python_version = "/path/to/venv/starter/bin/python")

@astamm
Copy link
Author

astamm commented Oct 19, 2023

Thanks for the quick reply! I indeed circumvented the issue by running

tensorflow::install_tensorflow(python_version = "3.9")

However I believe it could be nice to have it set by default even without running first

lapply(sprintf("%s:latest", c("3.8", "3.9", "3.10", "3.11", "3.12")), 
       reticulate::install_python))

@mitchellxh
Copy link

Hi,

Just want to add that I've come across a similar issue in getting this to install properly on a share HPC system. By default, even after trying setting up ~/.Renviron, reticulate's use_python(), or Sys.setenv(RETICULATE_PYTHON="/path/to/bin/python"), the install_tensorflow() command would default to the latest python version available on path.

The only way to circumvent this was by specifying within the command like so:
install_tensorflow(python_version = "/path/to/bin/python")

@t-kalinowski
Copy link
Member

t-kalinowski commented Dec 19, 2023

RETICULATE_PYTHON is for telling reticulate which python to bind to in the current R session, not for selecting which python to use as a venv starter when creating a new python installation.

If you're in an environment where there are already a few python versions installed and available, and reticulate::virtualenv_starter() is not finding them, you can set the env var
RETICULATE_VIRTUALENV_STARTER=paths or the R options(reticulate.virtualenv.starter = paths), where paths is : separated string of paths under which (potentially) multiple python versions can be found.

@mitchellxh
Copy link

Thanks for clarifying! This information was lacking from the RStudio TensorFlow install and custom install pages. As you clarified, the custom install page only describes specifying the python version that reticulate binds to the R session.

Since it is explicitly recommending running install_tensorflow(), I think it's assumed the python version reticulate binds will be used to create venvs. Not totally sure why that is not the default case?

Probably a question for the folks at reticulate...

@t-kalinowski
Copy link
Member

Thanks for the suggestion! This is now implemented in the dev version of reticulate - virtualenv_starter() will consult RETICULATE_PYTHON and use_python() when assembling the list of candidate python's for creating a venv.

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