Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:22:43+00:00 2026-05-31T11:22:43+00:00

import os from os.path import abspath, dirname import sys # Set up django project_dir

  • 0
import os
from os.path import abspath, dirname
import sys

# Set up django
project_dir = abspath(dirname(dirname(__file__)))
sys.path.insert(0, project_dir)
os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"

I did that, and I still get

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    from django.middleware.csrf import get_token
  File "/var/lib/system-webclient/system-webenv/lib/python2.6/site-packages/django/middleware/csrf.py", line 14, in <module>
    from django.utils.cache import patch_vary_headers
  File "/var/lib/system-webclient/system-webenv/lib/python2.6/site-packages/django/utils/cache.py", line 24, in <module>
    from django.core.cache import cache
  File "/var/lib/system-webclient/system-webenv/lib/python2.6/site-packages/django/core/cache/__init__.py", line 68, in <module>
    cache = get_cache(settings.CACHE_BACKEND)
  File "/var/lib/system-webclient/system-webenv/lib/python2.6/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/var/lib/system-webclient/system-webenv/lib/python2.6/site-packages/django/conf/__init__.py", line 38, 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

It was a small script calling some django functionality, but it is telling me ENVIRONMENT VARIABLE issue.

What can I do? I spent my whole afternoon reading many posts….

Thanks for helping! This was my 1st time hitting it.


The traceback. It doesn’t give raise our manual exception. It is giving the same exception as above.

webclient/main.py

import os
from os.path import abspath, dirname
import sys
path = '/var/lib/graphyte-webclient/webclient'
if path not in sys.path:
    sys.path.append(path)
sys.path.insert(0, path)
os.environ["DJANGO_SETTINGS_MODULE"] = "webclient.settings"
raise Exception("DJANGO_SETTINGS_MODULE = " + str(os.environ["DJANGO_SETTINGS_MODULE"]))

    .... other things

In manage.py shell

>>> from webclient.settings import settings
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: cannot import name settings

>>> import webclient
>>> webclient
<module 'webclient' from '/var/lib/system-webclient/webclient/../webclient/__init__.pyc'>

>>> import webclient.settings
>>> webclient.settings
<module 'webclient.settings' from '/var/lib/system-webclient/webclient/../webclient/settings.pyc'>

webclient/deploy/pinax.fcgi

import os
import sys

from os.path import abspath, dirname, join
from site import addsitedir

sys.path.insert(0, abspath(join(dirname(__file__), "../../")))

from django.conf import settings
os.environ["DJANGO_SETTINGS_MODULE"] = "webclient.settings"

sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

webclient/deploy/pinax.wcgi

import os
import sys

from os.path import abspath, dirname, join
from site import addsitedir

sys.path.insert(0, abspath(join(dirname(__file__), "../../")))

from django.conf import settings
os.environ["DJANGO_SETTINGS_MODULE"] = "webclient.settings"
#os.environ["SCRIPT_NAME"] = "/natrium"

sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

filesystem image

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:22:45+00:00Added an answer on May 31, 2026 at 11:22 am

    Add this to the top, it looks like the path to your settings file is not in your system path:

    path = '/path/to/mysite'
    if path not in sys.path:
       sys.path.append(path)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import sys sys.path.append('/home/myuser/svn-repos/myproject') from myproject.settings import * But, it says module not found when
from sys import argv from os.path import exists script, from_file, to_file = argv print
- import time import subprocess from os.path import expanduser chrome_path = expanduser('~\Local Settings\Application Data\Google\Chrome\Application\chrome.exe')
I have project Emle in Launchpad . I set it to import from emle.svn.sourceforge.net
views.py from django.shortcuts import render_to_response from django.shortcuts import get_object_or_404 from django.shortcuts import get_list_or_404 from
I'm working on an import (from Excel) dialog to select ranges of cells. When
I have a method I want to import from a DLL and it has
I will be doing an occiasional import from XML into core data. I have
In this situation I am trying to perform a data import from an XML
Here's the deal: A Github repo features a historical import from CVS, divided in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.