0

Currently my file structure looks like this:

\HelloWorld
 -helloWorld.py
 - __init__.py
  \api
   - __init__.py
   - userAPI.py
   - util.py

The code looks like the following:

HelloWorld.py:

import api.userAPI

def handler(event, context):
    api.userAPI.create_user()

userAPI.py

import util
def create_user():
    helper()
    print("creation")

util.py

def helper()::
    print("HI!")

However, I'm getting a " Unable to import module 'HelloWorld': No module named 'util'". I'm running it with Python3.8 and writing lambda code. HelloWorld.py is my lambda

Qwerty Qwerts
  • 1,521
  • 2
  • 9
  • 13
  • 1
    Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time). The answers there cover some common confusions about scripts vs modules and directories vs packages. Do note that imports _do not_ navigate directories. Python imports work by searching the Python path. `import x` doesn't mean "search for `x` in the same directory as the current file", it means "search for a top-level module named `x` on the Python path". – Brian61354270 Aug 16 '23 at 02:05
  • Based on the `__init__.py`, it looks like you want `HelloWorld` to be package. If that's the case, then _all_ of your imports should be of the form `import HelloWorld.x.y.z`, regardless of what file they're in. – Brian61354270 Aug 16 '23 at 02:09
  • It's more like HelloWorld is my lambda and it calls userAPI which calls upon utils – Qwerty Qwerts Aug 16 '23 at 03:27
  • @Brian61354270, I don't think that helpss very much as I'm doing this on a lambda, where os.getcwd() is /var/tasks – Qwerty Qwerts Aug 16 '23 at 22:40

0 Answers0