0

I have a Django project and the directory is as follows.enter image description here

There are a Python file named permissions.py and a module name permissions.I want to import permissions.helpers but it raises ImportError and the error message is cannot import name helpers.

The first element in sys.path is the project directory(the parent directory of myapp) as I expected.I thought Python Interpreter should try to find modules or files from sys.path but it seems to search in the current module first.Am i wrong and how can i import permissions.helpers without using absolute_import?

yychzjl
  • 39
  • 4
  • 1
    can you try with Relative import like `from .permissions import helpers`? – ruddra Jan 11 '21 at 09:40
  • Which module are you trying to use either `permissions` into? `from .persmissions import helper` or `from ..permissions import helpers` depending what is trying to use should work I think. – Jerakin Jan 11 '21 at 09:45
  • Actually `from ..permissions import helpers`.I tried but it raise `ValueError: Attempted relative import beyond toplevel package`. – yychzjl Jan 11 '21 at 09:51
  • Check if this helps you out... https://stackoverflow.com/questions/4383571/importing-files-from-different-folder – Laukey Jan 11 '21 at 09:53

0 Answers0