Getting started with ImJoy tutorial

Hi, I’m just starting to look at ImJoy, trying the tutorial at

At this point, “Calling Python from JavaScript”, do you need to start a new browser window or are you working in the previously-opened

Having chosen to create a new web-python Plugin and pasting in the sample code, I needed to add "requirements": ["numpy"], to fix the ModuleNotFoundError.

Then I created the getPlugin-demo plugin as described, but this failed to run with:

<getPlugin-demo>Error: Error: Error: Error: TypeError: calc_exp() takes 1 positional argument but 2 were given

Fixing this by adding ‘self’ to the calculator plugin:

async def calc_exp(self, x):

This doesn’t give the expected output. Message is:

Exp of 9 is function(){return new Promise(async(r,i)=>{const o=await n._wrap(,s=o.__transferables__;s&&delete o.__transferables__;const c=await n._wrap([r,i]);r.__promise_pair=c[1]._rvalue,i.__promise_pair=c[0]._rvalue;try{n._connection.emit({type:"callback",target_id:e,id:t,args:o,promise:c},s)}catch(e){i(`Failed to exectue remote callback ( id: ${t}).`)}})}

Thanks for your help,


Ah, I figured it out.
I needed to remove the async from calc_exp in calculator:

def calc_exp(self, x):

Hi @will-moore, sorry about the confusion, I will fix these issues in the docs.

There is another thing you need to be aware is that we don’t support asyncio (including asyn/await syntax) in web-python plugins. So you need to remove asyncio/async/await from the python example:

import numpy as np
from imjoy import api

class ImJoyPlugin():
    def setup(self):

    def run(self, ctx):

    def calc_exp(self, x):
        return np.exp(x)


I just fixed it in the docs with this PR.

1 Like

Well, it actually still works for me with the one async still in there at run:

    async def run(self, ctx):

Thanks for the PR.