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

Relative imports in Python packages do not work #1462

Open
lpsinger opened this issue Nov 17, 2023 · 1 comment
Open

Relative imports in Python packages do not work #1462

lpsinger opened this issue Nov 17, 2023 · 1 comment

Comments

@lpsinger
Copy link

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
@lpsinger
Copy link
Author

Note that absolute imports of modules that are defined locally within the Lambda don't work either. See nasa-gcn/gcn.nasa.gov#1678.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant