URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>

Trying to run the below code on a macbook pro with catalina os, RStudio Version 1.2.5019 & R 3.6.1 installed. have tried uninstalling everything and re-installing, updating xcode, accepting python certificate from Python 3, nothing seems to work.

title: 'Executive 1: Software Overview'
date: "r Sys.Date()"
output: html_document

#do not change this
knitr::opts_chunk$set(echo = TRUE)

NOTE: All instructions in capital letters indicate code that you should fill in with the appropriate information.

Set up your python

  • Install the reticulate package (do not include this code).
  • Load the reticulate library.
  • The first you set this up, you need to configure where your Python is located.
  • Run py_config() to find the python versions you have installed on your machine.
  • For example, here's mine:
python: /Users/bharadwajpopuri/.virtualenvs/r-reticulate/bin/python
libpython: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7.dylib
pythonhome: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7:/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7
version:        3.7.3 (default, Sep  5 2019, 17:14:41)  [Clang 11.0.0 (clang-1100.0.33.8)]
numpy:          /Users/bharadwajpopuri/.virtualenvs/r-reticulate/lib/python3.7/site-packages/numpy
numpy_version:  1.17.3

python versions found: 
  • Next, we want to configure which one to use.
  • If the one listed next to python on the top line is the one you want to use, you are all done.
  • If not, you will copy the path (i.e. /Users/b/...) and tell R to talk to that python instead.
  • To do that, you would use: use_python("PATH", required = TRUE).
  • However, you can't run use_python() after running py_config(). You will get an error message:
ERROR: The requested version of Python
('/Users/buchanan/anaconda3/bin/python') cannot be used, as
another version of Python ('/usr/bin/python') has already
been initialized. Please restart the R session if you need
to attach reticulate to a different version of Python.
Error in use_python("/Users/buchanan/anaconda3/bin/python", required = TRUE) : 
  failed to initialize requested version of Python
  • Click Session > Restart R.
  • Then use your use_python() code.
  • Do not include BOTH py_config() and use_python() in the same markdown. Once you know where your path is, just use use_python().
#use_python("/Users/bharadwajpopuri/.virtualenvs/r-reticulate/bin/python3",required = TRUE)

Let's do some R

  • In this chunk, we will load a dataset - use data(rock) to load it.
  • Use the head() function to print out the first six rows of the dataset.

Let's do some Python

  • First, let's install some packages.
  • You will need numpy, nltk, spacy, seaborn and pandas for starters.
  • You can check if you have them first by using py_module_avalable("PACKAGE").
  • If any of these return FALSE, then install them using py_install("PACKAGE").

Call a dataset in Python

  • First, load the seaborn library, it has several sample datasets. You load python packages by using import PACKAGE.
  • Then call the dots dataset by doing: VARNAME = PACKAGENAME.load_dataset("DATASETNAME").
  • To print out the first six rows, use the .head() function: VARNAME.head().
import seaborn
import spacy
dots = seaborn.load_dataset("dots")

QUESTION: Look in your environment window. What do you see?

Print out Python information in R

  • You can have the two environments interact. To print out information from Python in R: py$VARNAME.
  • Normally, to print out R dataset columns, you do DATAFRAME$COLUMN. Try to print out the time column from your dots variable (whatever you named it above).

Print our R in Python

  • When using R in Python, instead of $, we use . like this: r.VARNAME.
  • To print out a single column, you use DATAFRAME["COLUMNNAME"]. Try printing out the shape column in the rock dataset.

Get started with PyCharm!

  • Great job! Here's what you learned:
    • You know how to tell Rmarkdown which Python to use.
    • You know how to install and load the libraries in both languages.
    • You know how to load built in datasets in both languages.
    • You know how to print out data from one language to another.
  • Turn this document in for credit --> hit KNIT --> turn in the HTML file.
  • Be sure to fill in your name at the top!

Full Error Message

URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>

Detailed traceback:
File "", line 1, in
File "/Users/bharadwajpopuri/.virtualenvs/r-reticulate/lib/python3.7/site-packages/seaborn/utils.py", line 428, in load_dataset
urlretrieve(full_path, cache_path)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 247, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)

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