Cannot install reticulate and tensorflow in RStudio due to g++ command not found

I am trying to install tensorflow in R Studio through Linux terminal, by following the three methods mentioned in this link TensorFlow for R - Quick start, namely "auto", "virtualenv" and "conda". However, none of them worked.

Following the method "auto", we tried with the command:

tensorflow::install_tensorflow()

However, it gave an error related to the tensorflow version and I have tried with different versions of it:

> tensorflow::install_tensorflow()
Activated conda python: /root/.local/share/r-miniconda/envs/r-reticulate/bin/python
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
ERROR: Could not find a version that satisfies the requirement tensorflow==2.11.* (from versions: none)
ERROR: No matching distribution found for tensorflow==2.11.*
Error: Error installing package(s): "'tensorflow==2.11.*'"

Then, following the "virtualenv" method, it retrieved the same error as the "auto" technique:

> library(reticulate)
> virtualenv_create("r-reticulate", python = "/usr/bin/python3")
virtualenv: r-reticulate
> virtualenv_create("r-reticulate", python = "/usr/bin/python3")
virtualenv: r-reticulate
> library(tensorflow)
> install_tensorflow(envname = "r-reticulate")
Using virtual environment 'r-reticulate' ...
Collecting tensorflow==2.11.*
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Could not find a version that satisfies the requirement tensorflow==2.11.* (from versions: )
No matching distribution found for tensorflow==2.11.*
Error: Error installing package(s): "'tensorflow==2.11.*'"

Finally, I tried the "conda" alternative, conda_create("r-reticulate") , but it gave the same error as trying with the "auto" method:

> install_tensorflow(envname = "r-reticulate")
Using virtual environment 'r-reticulate' ...
Collecting tensorflow==2.11.*
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
  Could not find a version that satisfies the requirement tensorflow==2.11.* (from versions: )
No matching distribution found for tensorflow==2.11.*
Error: Error installing package(s): "'tensorflow==2.11.*'"

Moreover, I tried following the steps on this link Tensorflow setup on RStudio/ R | CentOS but we could not install the tensorflow on the new port.

For your information, there are two Python versions installed in the Linux OS, which are 3.6.8 and 2.7.5. The R Studio version is 4.1.3.

Your problem is that reticulate is trying to install tensorflow (python package) in version 2.11.* . This however fails because your "latest" python version is version 3.6.8. According to tensorflow · PyPI you can see that it requires python >= 3.7.

You have the following three options:

  1. Use install_tensorflow(method="conda") which will not only install the python packages but also downlod miniconda which contains a rather recent python version (it will be installed in your home-directory)
  2. Downgrade your R package to tensorflow 2.6.0 via remotes::install_version("tensorflow",version="2.6.0") and repeat the install_tensorflow()
  3. Upgrade or add a Python version larger than >= 3.7 and als repeat install_tensorflow()

Let me know if this helps,

Michael.

Neither option worked for me and I got these errors:

  1. tensorflow::install_tensorflow(method="conda")
    Activated conda python: /root/.local/share/r-miniconda/envs/r-reticulate/bin/python
    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
    WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
    WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
    WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
    WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
    ERROR: Could not find a version that satisfies the requirement tensorflow==2.11.* (from versions: none)
    ERROR: No matching distribution found for tensorflow==2.11.*
    Error: Error installing package(s): "'tensorflow==2.11.*'"

  2. Error in download_version_url(package, version, repos, type) :
    version '2.6.0' is invalid for package 'tensorflow'

  3. [root@sasgrid2 sas]# python3 --version
    Python 3.8.14
    [root@sasgrid2 sas]# python --version
    Python 3.8.14

tensorflow::install_tensorflow()
Activated conda python: /root/.local/share/r-miniconda/envs/r-reticulate/bin/python
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/tensorflow/
ERROR: Could not find a version that satisfies the requirement tensorflow==2.11.* (from versions: none)
ERROR: No matching distribution found for tensorflow==2.11.*
Error: Error installing package(s): "'tensorflow==2.11.*'"

What could I do to correct these errors?

Thanks in advance!

I am sorry to hear about those ongoing problems.

I am wondering if you are in an air-gapped or offline environment ? Are you aware of any such restrictions ? Or do you need to set a proxy to reach out to the internet ?

Let's try and do a simple test by downloading a small file from pypi via

wget https://files.pythonhosted.org/packages/69/dc/66544b793f5970aff328fb7c6f6a29bc33a8f1fb325f98394897f067c4ae/tensorflow-2.13.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

to see if this works (if wget is not installed, please try with curl -O instead - also please note that this is for the wrong architecture but it is small enough so you don't need to download the 500+ MB wheels for x86_64...

Let me know if this works or not.

I run the command you suggested but it gave an error, which is due to some Firewall restriction.

--2023-08-08 15:16:07--  https://files.pythonhosted.org/packages/69/dc/66544b793f5970aff328fb7c6f6a29bc33a8f1fb325f98394897f067c4ae/tensorflow-2.13.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Resolving files.pythonhosted.org (files.pythonhosted.org)... 151.101.65.55, 151.101.129.55, 151.101.193.55, ...
Connecting to files.pythonhosted.org (files.pythonhosted.org)|151.101.65.55|:443... connected.
Unable to establish SSL connection.

Do you think the errors mentioned before in the thread are due to Firewall restrictions?

Now, there is an error when trying to install reticulate in RStudio for then installing tensorflow and all the solutions I found on the web were related to installing the g++ but this is already installed:

install.packages("reticulate")
also installing the dependency ‘RcppTOML’

trying URL 'https://cran.rstudio.com/src/contrib/RcppTOML_0.2.2.tar.gz'
Content type 'application/x-gzip' length 141195 bytes (137 KB)

downloaded 137 KB

trying URL 'https://cran.rstudio.com/src/contrib/reticulate_1.31.tar.gz'
Content type 'application/x-gzip' length 1597525 bytes (1.5 MB)

downloaded 1.5 MB

  • installing source package ‘RcppTOML’ ...
    ** package ‘RcppTOML’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs
    g++-7 -std=gnu++17 -fPIC -std=gnu++17 -I"/opt/conda-envs/tf/lib/R/include" -DNDEBUG -I../inst/include -DTOML_ENABLE_FLOAT16=0 -I"/opt/conda-envs/tf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /opt/conda-envs/tf/include -I/opt/conda-envs/tf/include -Wl,-rpath-link,/opt/conda-envs/tf/lib -fpic -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /opt/conda-envs/tf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1589917437985/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/conda-envs/tf=/usr/local/src/conda-prefix -c RcppExports.cpp -o RcppExports.o
    /bin/sh: g++-7: command not found
    make: *** [RcppExports.o] Error 127
    ERROR: compilation failed for package ‘RcppTOML’
  • removing ‘/opt/conda-envs/tf/lib/R/library/RcppTOML’
    Warning in install.packages :
    installation of package ‘RcppTOML’ had non-zero exit status
    ERROR: dependency ‘RcppTOML’ is not available for package ‘reticulate’
  • removing ‘/opt/conda-envs/tf/lib/R/library/reticulate’
    Warning in install.packages :
    installation of package ‘reticulate’ had non-zero exit status

The downloaded source packages are in
‘/tmp/Rtmpg35a94/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done´´´

Do you any ideia how to solve this?

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.