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

import("asyncio") fails on Windows #1478

Closed
t-kalinowski opened this issue Sep 13, 2023 · 1 comment · Fixed by #1479
Closed

import("asyncio") fails on Windows #1478

t-kalinowski opened this issue Sep 13, 2023 · 1 comment · Fixed by #1479

Comments

@t-kalinowski
Copy link
Member

Tracking (rstudio/keras#1375), where reticulate::import("tensorflow") fails, I was able to narrow down to a smaller reprex using just the standard library:

import("asyncio"); #import("tensorflow")
Error in py_module_import(module, convert = convert) : 
  TypeError: the first argument must be callable
Run `reticulate::py_last_error()` for details.
> reticulate::py_last_error()

── Python Exception Message ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
  File "C:\Users\kalin\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\kalin\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
    module = hook()
  File "C:\Users\kalin\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\kalin\AppData\Local\R-RETI~1\R-RETI~1\pyenv\PYENV-~1\versions\310~1.11\lib\asyncio\__init__.py", line 47, in <module>
    from .windows_events import *
  File "C:\Users\kalin\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\kalin\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
    module = hook()
  File "C:\Users\kalin\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\kalin\AppData\Local\R-RETI~1\R-RETI~1\pyenv\PYENV-~1\versions\310~1.11\lib\asyncio\windows_events.py", line 25, in <module>
    from . import windows_utils
  File "C:\Users\kalin\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\kalin\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
    module = hook()
  File "C:\Users\kalin\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\kalin\AppData\Local\R-RETI~1\R-RETI~1\pyenv\PYENV-~1\versions\310~1.11\lib\asyncio\windows_utils.py", line 125, in <module>
    class Popen(subprocess.Popen):
TypeError: the first argument must be callable

── R Traceback ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    ▆
 1. └─reticulate::import("asyncio")
 2.   └─reticulate:::py_module_import(module, convert = convert)

It looks like this is due to #1458 (reverting the PR fixes the issue).

t-kalinowski added a commit that referenced this issue Sep 13, 2023
asyncio.windows_utils subclasses/aliases Popen like this:

```python
class Popen(subprocess.Popen)
  def __init__(...):
    ...
    try:
      super().__init__(...)
    ...

```

Calling `partial()` on Popen directly works when
using it like a function, but breaks when
subclassing Popen (like asyncio does).

Closes rstudio/keras#1375
Closes #1478
t-kalinowski added a commit that referenced this issue Sep 13, 2023
asyncio.windows_utils subclasses/aliases Popen like this:

```python
class Popen(subprocess.Popen)
  def __init__(...):
    ...
    try:
      super().__init__(...)
    ...

```

Calling `partial()` on Popen directly works when
using it like a function, but breaks when
subclassing Popen (like asyncio does).

Closes rstudio/keras#1375
Closes #1478
@philiporlando
Copy link

philiporlando commented Jan 12, 2024

I was experiencing similar issues with reticulate::import("asyncio") when using 1.32.0. Upgrading to 1.34.0 resolved this issue for me.

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

Successfully merging a pull request may close this issue.

2 participants