I've been running into some reticulate
trouble when trying to use tensorflow
. If I run a plain R session or plain Python session on the CLI I am able to install and use tensorflow.
library(reticulate) # loads fine
conda_create("r-reticulate") # seems to work
conda_install("r-reticulate", "scipy") # seems to work
conda_install("r-reticulate", "tensorflow") # fails
# Collecting package metadata (current_repodata.json): ...working... done # Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve. # Solving environment: ...working... failed with repodata from current_repodata.json, will retry with next repodata source. # # ResolvePackageNotFound: # - python=3.1 # # Error: one or more Python packages failed to install [error code 1]
Not sure what that's about, so then I try
use_condaenv("r-reticulate") # seems to work
py_install("tensorflow") # fails
which gives the error:
Error: could not find a Python environment for /opt/local/bin/python3.9
So then I tried:
virtualenv_create("rstudio-python-virtualenv")
which throws the error
ERROR: Failed cleaning build dir for numpy
Even though that failed, just for laughs I tried
virtualenv_install("rstudio-python-virtualenv", "tensorflow")
which throws
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
After some more troubleshooting I tried changing the Python interpreter specified in "Global Options" to these 2 new virtual environments created above. It had no effect on the error messages.
I also tried reticulate::py_install("tensorflow")
which throws:
Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve. Solving environment: ...working... failed with repodata from current_repodata.json, will retry with next repodata source. ResolvePackageNotFound: - python=3.1 Error: one or more Python packages failed to install [error code 1] >
CodePudding user response:
Apprently at least part of the problem was that conda_create
was creating environments based on versions of Python that were too new for the version of tensorflow
it was trying to install (i.e. Python v3.10.0). This worked:
conda_create("r-py-conda-3.6", python_version = "3.6")
conda_install(envname = "r-py-conda-3.6",
packages=("tensorflow"))