DJANGO_SETTINGS_MODULE How to configure
Question: I am working in a project with Django 1.8 and Python-3.4 I want install the
mockups package for automate the data creation in my application. I've
installed this package with `pip install django-mockups` and `easy_install
django-mockups`

I add the 'mockups' entry in my INSTALLED_APPS in my settings.py file

    
    
    INSTALLED_APPS = (
        'suit',
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'mockups',
        'tracks',
        'albums',
        'artists', 
        'userprofiles',
    )
    

I want to see in the django admin utility inside my console my commands
available in relation with my packages installed, but at the end, I get the
message of Note about of my environment variable `DJANGO_SETTINGS_MODULE` and
I cannot see the django-mockups package in the list

    
    
    (venv)➜  myproject  django-admin help 
    
    Type 'django-admin help <subcommand>' for help on a specific subcommand.
    
    Available subcommands:
    
    [django]
        check
        compilemessages
        createcachetable
        dbshell
        diffsettings
        dumpdata
        flush
        inspectdb
        loaddata
        makemessages
        makemigrations
        migrate
        runfcgi
        runserver
        shell
        showmigrations
        sql
        sqlall
        sqlclear
        sqlcustom
        sqldropindexes
        sqlflush
        sqlindexes
        sqlmigrate
        sqlsequencereset
        squashmigrations
        startapp
        startproject
        syncdb
        test
        testserver
        validate
    Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
    

(venv)➜ myproject

I check that django-mockups package is installed checking the following path
directories, that in fact, exists.

    
    
     /home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django_mockups-0.4.8.dist-info` and
     /home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups`
    

And `django-mockups` package is installed

    
    
    (venv)➜  mockups  pip freeze
    Django==1.8.2
    django-mockups==0.4.8
    django-suit==0.2.13
    Pillow==2.9.0
    wheel==0.24.0
    (venv)➜  mockups 
    

My `DJANGO_SETTINGS_MODULE` is set of this way: In the `manage.py` file

    
    
    #!/usr/bin/env python
    import os
    import sys
    
    if __name__ == "__main__":
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sfotipy.settings")
    
        from django.core.management import execute_from_command_line
    
        execute_from_command_line(sys.argv)
    

And in the wsgi.py

    
    
    """
    WSGI config for myproject project.
    
    It exposes the WSGI callable as a module-level variable named ``application``.
    
    For more information on this file, see
    https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
    """
    
    import os
    
    from django.core.wsgi import get_wsgi_application
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
    
    application = get_wsgi_application()
    

And finally when I try start the django server, I get this output:

    
    
    (venv)➜  myproject  ./manage.py runserver 
    /home/bgarcial/.virtualenvs/venv/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
      return f(*args, **kwds)
    
    Traceback (most recent call last):
      File "./manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
        utility.execute()
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
        django.setup()
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/apps/registry.py", line 85, in populate
        app_config = AppConfig.create(entry)
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/apps/config.py", line 86, in create
        module = import_module(entry)
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
      File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
      File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 1129, in _exec
      File "<frozen importlib._bootstrap>", line 1448, in exec_module
      File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/__init__.py", line 2, in <module>
        from mockups.factory import Factory
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/factory.py", line 1, in <module>
        from mockups import generators
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/generators.py", line 100, in <module>
        class StringGenerator(Generator):
      File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/generators.py", line 101, in StringGenerator
        coerce_type = unicode
    NameError: name 'unicode' is not defined
    (venv)➜  myproject 
    

How to can I set correctly my DJANGO_SETTINGS_MODULE environment variable? Is
this DJANGO_SETTINGS_MODULE configuration the origin of that mockups does not
work? Tanks a lot :)

Thanks


Answer: I find this [issue](https://github.com/sorl/django-mockups/issues/20) in
github.

~~Maybe~~ django-mockups is not support Python 3.

* * *

Python 3 change `unicode` to `str`, and the old `str` to `bytes`.

So if you run django-mockups with Python 3. `NameError` will be raised

As the traceback show, django-mockups is written in Python 2.

