2

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]
>
Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • I once run into a lot of troubles using conda, have you tried to use a plain fresh python install instead, and set it has the default environment for reticulate? – bricx Nov 15 '21 at 16:54
  • @bricx Interesting. Well I've tried Python 3.7 and 3.9 that were already installed on my system, then I did a fresh conda install and it installed 3.10. It looks like 3.10 may be too new for the conda version of tensorflow based on the dependency conflicts I'm seeing, so I'm going to try with like 3.6. – Hack-R Nov 15 '21 at 16:57

1 Answers1

1

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"))
Hack-R
  • 22,422
  • 14
  • 75
  • 131