python-eel/Eel

AttributeError: module 'eel' has no attribute 'receiveLogFromPython'

Open

#699 opened on Aug 22, 2023

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Python (570 forks)batch import
help wanted

Repository metrics

Stars
 (5,980 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Describe the problem I am developing an app with React and eel. I am trying to import a JS function in Python. In development it works fine, but when running the debugger or build, I get the error: AttributeError: module 'eel' has no attribute 'receiveLogFromPython'.

Code snippet(s) I export the receiveLogFromPython function from my AppContext.js as follows:

function receiveLogFromPython(message) {
  if (shouldCancelRef.current) {
    return;
   }
   showLogAsNotification(message);
}
window.eel.expose(receiveLogFromPython);

This is the file utilities.py which is where I call the function in receiveLogFromPython:

import eel

@eel.expose
def separate_pdf(filepath, temp):
    delete_contents(temp)
    with Image(filename=filepath, resolution=300) as pdf:
        pdf_images = pdf.sequence
        for i, pdf_image in enumerate(pdf_images):
            with Image(image=pdf_image) as img:
                img.save(filename=os.path.join(temp, f"image{i:02d}.png"))
                msg = f"Saved image{i:02d}.png to temporary folder {temp}"
               # Here is the function
                eel.receiveLogFromPython(msg)
    images = [os.path.join(temp, f)
              for f in os.listdir(temp) if f.endswith(".png")]
    return images

Finally, my Main.py file:

# Use latest version of Eel from parent directory
sys.path.insert(1, '../../')

def start_eel(develop):
    """Start Eel with either production or development configuration."""

    if develop:
        directory = 'src'
        app = None
        page = {'port': 3000}
    else:
        directory = 'build'
        app = 'chrome'
        page = 'index.html'

    eel.init(directory, ['.tsx', '.ts', '.jsx', '.js', '.html'])

    print("Application running...")

    eel_kwargs = dict(
        host='localhost',
        port=8080,
        size=(1380, 900),
    )
    eel.start(page, mode=app, **eel_kwargs)


if __name__ == '__main__':
    import sys

    # Set the correct working directory
    if getattr(sys, 'frozen', False):
        # Set the working directory to the bundle resource path
        os.chdir(sys._MEIPASS)
    else:
        os.chdir(os.path.dirname(os.path.abspath(__file__)))

    # Pass any second argument to enable debugging
    start_eel(develop=len(sys.argv) == 2)

As I mentioned before, the function works correctly while I am developing. But when I do the build or activate the VSCode debugger, it returns the error I mentioned before. My theory is that when I do the build or debug, it doesn't get to read the JS function properly, and in eel.receiveLogFromPython(msg) it takes it as if it was native to eel. I have searched for the same problem in other forums and posts in this repository, but so far I did not find any satisfactory result. So I would greatly appreciate if you can give me a hand.

Desktop (please complete the following information):

  • OS: Windows 10 Enterprise 64 bits
  • Browser Chrome
  • Version 116.0.5845.97 (Build oficial) (64 bits)

Contributor guide