Skip to content

Relative imports in Python packages do not work #1462

Description

@lpsinger

Describe the issue
According to https://arc.codes/docs/en/guides/developer-experience/dependency-management#relative-modules-%26-code-sharing-1, one can import relative modules in Lambdas (as in import .foo). First of all, the sample code in the documentation is not valid Python syntax:

>>> import .foo
  File "<stdin>", line 1
    import .foo
           ^
SyntaxError: invalid syntax

But secondly, the correct syntax, from . import foo, does not work in an Architect-managed Lambda. It fails with the following error message:

ImportError: attempted relative import with no known parent package

Steps to reproduce

  1. Clone https://github.com/nasa-gcn/arc-python-example.
  2. Run npm install.
  3. Run npm start.
  4. Open a browser and navigate to http://localhost:3333/.

Expected behavior
Browser should display JSON response: {"hello": "world"}

Screenshots
Screenshot 2023-11-17 at 10 17 05

Desktop
Please complete the following information (if appropriate):

  • OS: macOS
  • Browser Safari

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions