TypeError: relative imports require the package argument in python
<p>I just started learning Python(2.7) and facing an issue. I am using windows 10.</p>

<p>I have created a virtual environment(c:\virtualenvs\testenv) and activated it. My app folder path is c:\pyprojects\pytest. This folder has got requirements.txt with all the packages listed.</p>

<p>The prompt looks like</p>

<pre><code>(testenv) c:\pyprojects\pytest\pip install -r requirements.txt
</code></pre>

<p>It installs all the required packages successfully under testenv. Then I ran the following command</p>

<pre><code>(testenv) c:\pyprojects\pytest\python manage.py runserver
</code></pre>

<p>and got the following error--</p>

<pre><code>Unhandled exception in thread started by &lt;function wrapper at 0x03ABF8F0&gt;
Traceback (most recent call last):

  File "C:\virtualenvs\testenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\virtualenvs\testenv\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
    autoreload.raise_last_exception()
  File "C:\virtualenvs\testenv\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "C:\virtualenvs\testenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\virtualenvs\testenv\lib\site-packages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\virtualenvs\testenv\lib\site-packages\django\apps\registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "C:\virtualenvs\testenv\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "c:\python27\Lib\importlib\__init__.py", line 30, in import_module
    raise TypeError("relative imports require the 'package' argument")
TypeError: relative imports require the 'package' argument
</code></pre>

<p>Now I checked the file -- C:\Python27\Lib\importlib__init__.py and it says </p>

<pre><code> if name.startswith('.'):
        if not package:
            raise TypeError("relative imports require the 'package' argument")
        level = 0
        for character in name:
            if character != '.':
                break
            level += 1
        name = _resolve_name(name[level:], package, level)
    __import__(name)
    return sys.modules[name]
</code></pre>

<p>There is no file in my app folder specially settings.py which starts with dot. Is it that my APP folder is not included in main python path? or I am missing something.</p>

<p>Any help is highly appreciated.</p>

<p>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.</p>

python django python-2.7