Relative imports require the 'package' argument Relative imports require the 'package' argument python python

Relative imports require the 'package' argument


I came to this question via Google, so I'll answer what helped me (not directly related to the question).

I use importlib to dynamically import sub-packages given by a string.

import importlibmodule_name = 'subpackage.i.import'special_module = importlib.import_module(module_name, package=None)

This simply has to be adjusted to

import importlibmodule_name = 'subpackage.i.import'special_module = importlib.import_module(module_name, package='my_current_pkg')


DJANGO_SETTINGS_MODULE is expected to be a Python module identifier, not a filesystem path. Looking at the django/conf/__init__py file, it seems that a relative path to your settings module won't work there. You will need to move it below a directory listed in your sys.path, or you should add a parent directory to your sys.path and reference your settings module from there.


You can also get this error simply if you have a typo in where you're specifying your settings file name.