Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reticulate python code fails in Rstudio but nor R terminal? #1691

Closed
MatthieuStigler opened this issue Nov 1, 2024 · 4 comments
Closed

Reticulate python code fails in Rstudio but nor R terminal? #1691

MatthieuStigler opened this issue Nov 1, 2024 · 4 comments

Comments

@MatthieuStigler
Copy link

I am using reticulate to access the google earthengine API calling reticulate::py_run_string("import ee; ee.Authenticate()"). (doing this with reticulate as I am facing issue with rgee) Curiously enough, the command runs fine when launched in the R terminal, but not from Rstudio.

Any idea of what could be causing this?

The command is (see below for details on ee):

reticulate::use_condaenv("~/programs/anaconda3/envs/ee")
reticulate::py_run_string("import ee; ee.Authenticate()")

I get the error message when running from Rstudio:

Exception ignored in PyObject_HasAttrString(); consider using PyObject_HasAttrStringWithError(), PyObject_GetOptionalAttrString() or PyObject_GetAttrString():
AttributeError: 'NoneType' object has no attribute 'context'
Error in py_run_string_impl(code, local, convert) :
ImportError: /usr/lib/x86_64-linux-gnu/libcrypto.so.3: version OPENSSL_3.3.0' not found (required by /home/matifou/programs/anaconda3/envs/ee/lib/python3.13/lib-dynload/_ssl.cpython-313-x86_64-linux-gnu.so) Run reticulate::py_last_error()` for details.

This is quite troubling as indeed, my openssl cversion on this Ubuntu 24.04 machine is 3.0.13, but not sure why the problem does not happen when launchign the same command from a plain R terminal?

And reticulate::py_last_error() gives:

reticulate::py_last_error()
── Python Exception Message ─────────────────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 122, in _find_and_load_hook
return _run_hook(name, _hook)
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 96, in _run_hook
module = hook()
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 120, in _hook
return find_and_load(name, import)
File "/home/matifou/programs/anaconda3/envs/ee/lib/python3.13/site-packages/ee/init.py", line 16, in
from ee import batch
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 122, in _find_and_load_hook
return _run_hook(name, _hook)
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 96, in _run_hook
module = hook()
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 120, in _hook
return find_and_load(name, import)
File "/home/matifou/programs/anaconda3/envs/ee/lib/python3.13/site-packages/ee/batch.py", line 17, in
from ee import _cloud_api_utils
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 122, in _find_and_load_hook
return _run_hook(name, _hook)
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 96, in _run_hook
module = hook()
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 120, in _hook
return find_and_load(name, import)
File "/home/matifou/programs/anaconda3/envs/ee/lib/python3.13/site-packages/ee/_cloud_api_utils.py", line 17, in
import google_auth_httplib2
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 122, in _find_and_load_hook
return _run_hook(name, _hook)
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 96, in _run_hook
module = hook()
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 120, in _hook
return find_and_load(name, import)
File "/home/matifou/programs/anaconda3/envs/ee/lib/python3.13/site-packages/google_auth_httplib2.py", line 24, in
import httplib2
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 122, in _find_and_load_hook
return _run_hook(name, _hook)
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 96, in _run_hook
module = hook()
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 120, in _hook
return find_and_load(name, import)
File "/home/matifou/programs/anaconda3/envs/ee/lib/python3.13/site-packages/httplib2/init.py", line 41, in
import ssl
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 122, in _find_and_load_hook
return _run_hook(name, _hook)
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 96, in _run_hook
module = hook()
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 120, in _hook
return find_and_load(name, import)
File "/home/matifou/programs/anaconda3/envs/ee/lib/python3.13/ssl.py", line 100, in
import _ssl # if we can't import it, let the error propagate
^^^^^^^^^^^
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 122, in _find_and_load_hook
return _run_hook(name, _hook)
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 96, in _run_hook
module = hook()
File "/usr/lib/R/site-library/reticulate/python/rpytools/loader.py", line 120, in _hook
return find_and_load(name, import)
ImportError: /usr/lib/x86_64-linux-gnu/libcrypto.so.3: version `OPENSSL_3.3.0' not found (required by /home/matifou/programs/anaconda3/envs/ee/lib/python3.13/lib-dynload/_ssl.cpython-313-x86_64-linux-gnu.so)

── R Traceback ──────────────────────────────────────────────────────────────────────────────────────────────────

  1. └─reticulate::py_run_string("import ee; ee.Authenticate()")
  2. └─reticulate:::py_run_string_impl(code, local, convert)
    See reticulate::py_last_error()$r_trace$full_call for more details.

where ee is created as:

conda create --name ee
conda config --add channels conda-forge
conda install earthengine-api
@t-kalinowski
Copy link
Member

Exception ignored in PyObject_HasAttrString(); consider using PyObject_HasAttrStringWithError(

This is a new error with Python 3.13. You can work around it for now by downgrading Python to 3.12, or installing the development version of reticulate, where this is fixed.

Also, the ssl issues is unrelated, but can probably be easily resolved by not using conda and switching to reticulate::install_python(), or, if on Linux, using the system Python or the prebuild Python binaries from https://github.com/rstudio/python-builds.

@MatthieuStigler
Copy link
Author

hi @t-kalinowski

thanks a lot for the fast reply! Using a conda environment with python 3.12 indeed solved the issue in Rstudio.

I'm still puzzled that it worked even with python 3.13 in the terminal but not in rstudio. Does that make sense to you, knowing that's the same environment?

Thanks!

@t-kalinowski
Copy link
Member

It's because the IDE is evaluating additional code in the background, e.g., probing objects to populate the Variables Pane or generate autocompletions, and those background R calls are causing the Python C internals to emit the warnings.

@MatthieuStigler
Copy link
Author

excellent, thanks for the additional explanation, much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants