problem with tensorflow 2.10 and rstudio

Hi, i can't manage to make tensorfow work inside Rstudio in windows 11
i have a r-tensorflow conda environment with tensorflow 2.10 working
if i use R directly without Rstudio i can load keras and tensorflow packages and it works, but when i use rstudio it does not work. The error i have is

library(tensorflow)
Error: package or namespace load failed for β€˜tensorflow’:
.onLoad failed in loadNamespace() for 'tensorflow', details:
call: py_module_import(module, convert = convert)
error: NameError: name 'base_events' is not defined
Run reticulate::py_last_error() for details.

reticulate:::py_last_error()

── Python Exception Message ─────────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in hook
return find_and_load(name, import)
File "C:\Users\fabie\MINICO~1\envs\R-TENS~1\lib\site-packages\tensorflow_init
.py", line 37, in
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in _hook
return find_and_load(name, import)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in hook
return find_and_load(name, import)
File "C:\Users\fabie\MINICO~1\envs\R-TENS~1\lib\site-packages\tensorflow\python_init
.py", line 104, in
from tensorflow.python.platform import test
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in _hook
return find_and_load(name, import)
File "C:\Users\fabie\MINICO~1\envs\R-TENS~1\lib\site-packages\tensorflow\python\platform\test.py", line 20, in
from tensorflow.python.framework import test_util as _test_util
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in _hook
return find_and_load(name, import)
File "C:\Users\fabie\MINICO~1\envs\R-TENS~1\lib\site-packages\tensorflow\python\framework\test_util.py", line 33, in
from absl.testing import parameterized
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in _hook
return find_and_load(name, import)
File "C:\Users\fabie\MINICO~1\envs\R-TENS~1\lib\site-packages\absl\testing\parameterized.py", line 222, in
from absl.testing import absltest
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in _hook
return find_and_load(name, import)
File "C:\Users\fabie\MINICO~1\envs\R-TENS~1\lib\site-packages\absl\testing\absltest.py", line 46, in
from unittest import mock # pylint: disable=unused-import Allow absltest.mock.
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in _hook
return find_and_load(name, import)
File "C:\Users\fabie\MINICO~1\envs\R-TENS~1\lib\unittest\mock.py", line 26, in
import asyncio
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\fabie\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in hook
return find_and_load(name, import)
File "C:\Users\fabie\MINICO~1\envs\R-TENS~1\lib\asyncio_init
.py", line 27, in
all = (base_events.all +
NameError: name 'base_events' is not defined

── R Traceback ──────────────────────────────────────────────────────────────────────────────────────────
β–†

  1. └─reticulate::import("tensorflow")
  2. └─reticulate:::py_module_import(module, convert = convert)

of so it seems that the asyncio package can't be loaded by rstudio and consequently tensorflow can t be imported in Rstudio :
import("asyncio")
Error in py_module_import(module, convert = convert) :
NameError: name 'base_events' is not defined
Run reticulate::py_last_error() for details.

but if i import it from R directly the import works so it seems rstudio related.
can someone help on this problem ?
Thank you very much !

1 Like

Thank you for the report! This has been fixed in the development version of reticulate. Please install it with:

pak::pak("rstudio/reticulate")
2 Likes

it works now ! Thank you sooo much !!!

1 Like

This topic was automatically closed 21 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.