Search code examples
pythonpython-3.xdjangodjango-modelsvirtualbox

sys.path don't locate local dir


I've been trying to import a models file inside a seeder command.

I've tried from ...models import Player, from winners.models import Player added __init__.py everything that could be possible right.

And I keep getting or ModuleNotFoundError: No module named 'winners' or ImportError: attempted relative import with no known parent package

Although when I print the sys.path the local project ain't there. I've just started working on kali VirtualBox, could it be something wrong with the configuration?

enter image description here


Solution

  • Since models.py is in the same folder as your script, it would be sufficient to use the following statement, without adding your folder location to sys.path:

    from models import Player
    

    Alternatively, you could set the sys.path to the path ending in "olympic" (not "winners", since you want to refer to that folder in your from statement) to allow for the following:

    from winners.models import Player