rstudio/keras3

disable SSL verification when installing keras and tensorflow for R?

wisamb opened this issue · 2 comments

wisamb commented

Is there a way to disable SSL verification when installing keras and tensorflow for R? I am running into an SSL verification issue when I installed keras and tensorflow in R and also in Python. In Anaconda, I disabled SSL verification in the settings and was able to install keras and tensorflow. Is there a way to do the same in R. The following is the error that I am getting in R:

> install_keras(method = "virtualenv",tensorflow = "2.7")
Virtual environment "r-tensorflow" removed.
Using Python: C:/Program Files/Python311/python.exe
Creating virtual environment "r-tensorflow" ...
+ "C:/Program Files/Python311/python.exe" -m venv "C:/Users/Wisam.Barkho/Documents/.virtualenvs/r-tensorflow"
Done!
Installing packages: pip, wheel, setuptools
+ "C:/Users/Wisam.Barkho/Documents/.virtualenvs/r-tensorflow/Scripts/python.exe" -m pip install --upgrade pip wheel setuptools
Requirement already satisfied: pip in c:\users\wisam~1.bar\docume~1\virtua~1\r-tens~1\lib\site-packages (23.1.2)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/pip/
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='[pypi.org](http://pypi.org/)', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))) - skipping
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/wheel/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/wheel/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/wheel/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/wheel/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/wheel/
Could not fetch URL https://pypi.org/simple/wheel/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='[pypi.org](http://pypi.org/)', port=443): Max retries exceeded with url: /simple/wheel/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))) - skipping
ERROR: Could not find a version that satisfies the requirement wheel (from versions: none)
ERROR: No matching distribution found for wheel
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='[pypi.org](http://pypi.org/)', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))) - skipping
Error: Error installing package(s): "pip", "wheel", "setuptools"

My guess is that there is a corporate firewall interfering with pip downloads.

Do the same commands fail if you open up cmd.exe and run them?

"C:/Program Files/Python311/python.exe" -m venv "C:/Users/Wisam.Barkho/Documents/.virtualenvs/r-tensorflow"

"C:/Users/Wisam.Barkho/Documents/.virtualenvs/r-tensorflow/Scripts/python.exe" -m pip install --upgrade pip wheel setuptools

"C:/Users/Wisam.Barkho/Documents/.virtualenvs/r-tensorflow/Scripts/python.exe" -m pip install --upgrade tensorflow

If yes, then maybe manually adding trusted hosts to pip config may fix the issue https://stackoverflow.com/a/67796873/5128728

Or passing some variation of trusted-hosts to pip, either via pip options like

install_tensorflow(pip_options = "--trusted-hosts=pypi.python.org")

or by setting an env var

Sys.setenv(PIP_TRUSTED_HOSTS="pypi.python.org")
install_tensorflow()

You may have to confer with your IT department or Python-using colleagues for how to install pip packages with the corporate firewall settings.

wisamb commented

Yes, I am getting the same errors when running those commands from cmd.exe. The solution from StackOverflow worked (didn't try the others), not in standalone RStudio but when launching RStudio through Anaconda. Thank you! Been trying to get this to work forever!