[Python] Python ModuleNotFoundError cannot be excepted: No module named 'awsglue' when it is...

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    When running python scripts locally, I frequently need to use internal_lib.py which as part of its dependencies includes the following:

    try:
    from awsglue.utils import getResolvedOptions
    except (ImportError, ModuleNotFoundError) as e:
    pass


    However, when I run

    import internal_lib


    at the beginning of any script execution, despite specifically excepting the ModuleNotFoundError error, it errors out with:

    Exception has occurred: ModuleNotFoundError
    No module named 'awsglue'
    File "/Users/user/repos/repo/functions/internal_lib.py", line 18, in <module>
    from awsglue.utils import getResolvedOptions
    File "/Users/xx/repos/repo/functions/internal_lib.py", line 19, in <module>
    import internal_lib
    ModuleNotFoundError: No module named 'awsglue'


    If it's relevant this is python 3.12.9 on MacOS 15.3.1 (24D70), M2 Pro. This error happens the same way when I directly run those 4 lines FWIW. My goal is to successfully ignore the ModuleNotFoundError without needing to comment out the problematic lines, although I would also accept being able to install awsglue locally instead.

    Continue reading...

Compartilhe esta Página