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

Not work in pyodide #553

Open
Nanguage opened this issue Dec 25, 2023 · 1 comment
Open

Not work in pyodide #553

Nanguage opened this issue Dec 25, 2023 · 1 comment

Comments

@Nanguage
Copy link

Nanguage commented Dec 25, 2023

I tried to run imjoy-rpc in the pyodide environment:

import micropip
await micropip.install("imjoy-rpc")
from imjoy_rpc import api


class Plugin:
    async def setup(self):
        print("setup")

    async def run(self, ctx):
        print("run")
        print(ctx)

api.export(Plugin())

but the following error occurred.

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/lib/python3.11/site-packages/imjoy_rpc/werkzeug/local.py", line 349, in __getattr__
    return getattr(self._get_current_object(), name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/imjoy_rpc/__init__.py", line 46, in __getattr__
    setup_connection(_rpc_context, connection_type, logger)
  File "/lib/python3.11/site-packages/imjoy_rpc/utils.py", line 583, in setup_connection
    manager.start(
  File "/lib/python3.11/site-packages/imjoy_rpc/connection/pyodide_connection.py", line 79, i
n start
    raise ex
  File "/lib/python3.11/site-packages/imjoy_rpc/connection/pyodide_connection.py", line 75, i
n start
    self._create_new_connection(target, on_ready_callback, on_error_callback)
  File "/lib/python3.11/site-packages/imjoy_rpc/connection/pyodide_connection.py", line 91, i
n _create_new_connection
    connection = PyodideConnection(self.default_config)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/imjoy_rpc/connection/pyodide_connection.py", line 182, 
in __init__
    self._post_message = js.sendMessage
                         ^^^^^^^^^^^^^^
AttributeError: sendMessage

Do I need to make some settings in the JS environment? If so, how should I do it?

Environment: https://pyodide.org/en/stable/console.html

@oeway
Copy link
Contributor

oeway commented Dec 26, 2023

You will need to load the imjoy core in the web page, so imjoy-rpc can connect to it. In that case, you can just use imjoy-core and load a plugin with type=web-python, this will automatically run Python plugin in pyodide.

If you don't want to do anything in the pyodide env, it's easier to just use imjoy_rpc.hypha to connect to the hypha server. Then you will have a system similar to imjoy.

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