Installing python tensorflow with Rstudio

I have Rstudio version 2024.12.1 Build 563 installed. I have theR packages tensorflow and keras installed. I would like to work with python code for tensorflow and keras. I am trying to get started with python code using Rstudio.
I am not able to install the python packages tensorflow and keras. I show below my attempts:

#library(keras)
#library(tensorflow)
library(reticulate) # No error messages
py_config()
python: C:/AnacondaF/python.exe
libpython: C:/AnacondaF/python312.dll
pythonhome: C:/AnacondaF
version: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct 4 2024, 13:17:27) [MSC v.1929 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/AnacondaF/Lib/site-packages/numpy
numpy_version: 1.26.4

NOTE: Python version was forced by RETICULATE_PYTHON

path_to_python <- "C:/AnacondaF/python.exe"
virtualenv_create("r-reticulate", python = path_to_python)
virtualenv: r-reticulate
install_tensorflow(envname = "r-reticulate")
Error in install_tensorflow(envname = "r-reticulate") :
could not find function "install_tensorflow"
py_install("tensorflow",envname="r-reticulate",method="conda")

  • "C:/AnacondaF/condabin/conda.bat" install --yes --name r-reticulate -c conda-forge tensorflow
    Channels:
  • conda-forge
  • pymks
  • anaconda-fusion
  • defaults
    Platform: win-64
    Collecting package metadata (repodata.json): ...working... done
    Solving environment: ...working... warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
    failed

LibMambaUnsatisfiableError: Encountered problems while solving:

  • package tensorflow-1.7.0-0 requires tensorflow-base 1.7.0, but none of the providers can be installed

Could not solve for environment specs
The following packages are incompatible
├─ pin-1 is installable and it requires
│ └─ python 3.13.* , which can be installed;
└─ tensorflow is not installable because there are no viable options
├─ tensorflow [0.12.1|1.0.0|...|1.9.0] would require
│ └─ python [3.5* |3.5.* |>=3.5,<3.6.0a0 ], which conflicts with any installable versions previously reported;
├─ tensorflow [1.10.0|1.13.1|...|1.9.0] would require
│ ├─ python >=3.6,<3.7.0a0 , which conflicts with any installable versions previously reported;
│ └─ tensorflow-base [1.13.1 py36_4|1.13.1 py36_5|...|1.14.0 py36h9f0ad1d_0], which requires
│ └─ python >=3.6,<3.7.0a0 , which conflicts with any installable versions previously reported;
├─ tensorflow [1.13.1|1.14.0|...|2.9.1] would require
│ ├─ python [3.7.* |>=3.7,<3.8.0a0 ], which conflicts with any installable versions previously reported;
│ └─ tensorflow-base [1.13.1 py37_7|1.14.0 py37hc8dfbb8_0], which requires
│ └─ python >=3.7,<3.8.0a0 , which conflicts with any installable versions previously reported;
├─ tensorflow [1.10.0|1.11.0|...|2.1.0] would require
│ └─ python [3.6* |3.6.* ], which conflicts with any installable versions previously reported;
├─ tensorflow [1.7.0|1.7.1|1.8.0] would require
│ └─ tensorflow-base [1.7.0 |1.7.1 |1.8.0 ] but there are no viable options
│ ├─ tensorflow-base [1.7.0|1.7.1|1.8.0] would require
│ │ └─ python >=3.5,<3.6.0a0 , which conflicts with any installable versions previously reported;
│ └─ tensorflow-base [1.13.1|1.13.2|...|1.8.0], which cannot be installed (as previously explained);
├─ tensorflow [2.10.0|2.8.2|2.9.1] would require
│ └─ python 3.10.* , which conflicts with any installable versions previously reported;
├─ tensorflow [2.10.0|2.3.0|...|2.9.1] would require
│ └─ python 3.8.* , which conflicts with any installable versions previously reported;
└─ tensorflow [2.10.0|2.5.0|2.6.0|2.8.2|2.9.1] would require
└─ python 3.9.* , which conflicts with any installable versions previously reported.

Pins seem to be involved in the conflict. Currently pinned specs:

  • python 3.13.* (labeled as 'pin-1')

Error: one or more Python packages failed to install [error code 1]

Why am I not able to install the python packages? Please advise.

Your pinned Python version (3.13) is not compatible, current latest TF-2.19 requires Python 3.9–3.12 and for Windows builds of TensorFlow conda packages you'd need to go back to at least Python 3.10

  • from conda-forge you'd get tensorflow[1.14.0] that requites python [3.7.* ]
  • latest from main channel is tensorflow [2.10.0], requiring python [3.10.* ] (there are also builds for 3.8 & 3.9).

Is Anaconda (or conda in general) one of your requirements? Current reticulate version prefers uv-backed ephemeral Python environments over conda / venv . If this sounds like an option, you might find Installation Issue - no valid installation of tensorflow · Issue #622 · rstudio/tensorflow · GitHub to be helpful (remove environments created by reticulate , install tensorflow (the R package) from github and set release date constraints for pip packages -- some people (incl. me) are having issues with TF-2.19 on Windows)

Thanks for your response. They are very helpful. However, I must make it clear that I am a beginner when it comes to tensorflow, python and Rstudio. I have the following questions:

  1. In response to your question about Anaconda, I will say that I do not have any specific requirements. I am prepared to do what it takes to have a smooth running Rstudio, python and its packages that includes tensorflow.

  2. You say that TF-2.19 is not compatible with Python 3.13.*. So, what are my options? Shall I install a previous version of python? Which one?

  3. You say that reticulate prefers uv- backed ephemeral Python environments? I am afraid that I do not follow. You seem to imply that conda/venv is not preferred. What does this mean in concrete terms? Shall I uninstall Anaconda and go for an alternative? I am prepared to do this if I get some handholding advice on what I should do. Or, is there some safe option with Anaconda (with a previous version of Python that is compatible with TF)?

  4. You seem to say that it is better to avoid virtual environments created by reticulate. Is this a general comment on virtual environments, or just those created with reticulate?

  5. I am working on windows. I have tensorflow already installed. Is it necessary to specifically install from github?

  6. You require that I set release date constraints for pip packages. Please let me know how I can do this.

  7. Your suggestion - latest from main channel is tensorflow [2.10.0], requiring python [3.10.* ]. How do I specify main channel?

  8. As you can see, I am totally out of my depth here. I would appreciate it if you can help me with basic step-by-step instructions.

Thanks a lot for your help.