When trying to install django tagging Im getting the following error :

[root@Fileserver django-tagging]# pwd
/opt/django/djangoblog/django-tagging

[root@Fileserver django-tagging]# python setup.py install
Traceback (most recent call last):
  File "setup.py", line 49, in ?
    version_tuple = __import__('tagging').VERSION
  File "/opt/django/djangoblog/django-tagging/tagging/__init__.py", line 3, in ?
    from tagging.managers import ModelTaggedItemManager, TagDescriptor
  File "/opt/django/djangoblog/django-tagging/tagging/managers.py", line 5, in ?
    from django.contrib.contenttypes.models import ContentType
  File "/usr/lib/python2.4/site-packages/django/contrib/contenttypes/models.py", line 1, in ?
    from django.db import models
  File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line 14, in ?
    if not settings.DATABASES:
  File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

Ive tried a number of online hints and tips but still have yet to resolve this. Can anyone help ?

Dani AI

Generated

Short diagnosis for (and a follow-up to ): the install run is triggering an import of the tagging package at build time, and that package imports Django internals which expect Django settings to be configured. When no settings module is available, Django raises an ImportError about the settings environment. Django requires either an environment variable pointing to a settings module or an explicit settings configuration before any code reads settings. (docs.djangoproject.com)

Quick concrete fixes (fastest first):

  • Preferred: install the released package with pip so a wheel/source distribution is used instead of importing the package from the working tree:

    python -m pip install django-tagging

    Pip will fetch a prebuilt wheel when available and avoid executing package imports during installation. (pip.pypa.io)

  • If installing from the checked-out source, set the Django settings module (or provide a minimal settings) in the environment before running setup so Django won’t fail when the package metadata is imported:

    export DJANGO_SETTINGS_MODULE=mysite.settings
    python setup.py install

    Alternatively, point the variable at a tiny settings module that defines basic items (e.g. a minimal DATABASES and INSTALLED_APPS) so imports succeed. (docs.djangoproject.com)

Longer-term fix: change the project’s setup.py so it does not import the package to obtain metadata (version, etc.). Read the version string from a file (or parse init.py) instead of importing the package at setup time—this avoids pulling runtime dependencies during build. The Python packaging guide documents safe single-source patterns for versioning. Example pattern to extract a version without importing:

def get_version(path):
    for line in open(path):
        if line.startswith("__version__"):
            return line.split("=",1)[1].strip().strip('"\'')

Editing setup.py requires care, but it prevents this class of install-time import errors. (daobook.github.io)

Notes: prefer using isolated environments (virtualenv / venv) for installs; modifying setup.py or setting DJANGO_SETTINGS_MODULE is appropriate only when aware of the effects on the build/install process.

What of these hints you tried?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.