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 8158853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:44:43+00:00 2026-06-06T17:44:43+00:00

I have a python script that runs on a cron job. The script uses

  • 0

I have a python script that runs on a cron job. The script uses the django ORM of a related web portal for db calls. However, I am having a tough time running the script from command line. At the top of the script I have:

import sys
sys.path.append('/Users/david542/Desktop/project/')
from project.home.models import Title, Order

And when I try running the script:

  File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
  File "/Library/Python/2.7/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

It seems I need to set the DJANGO_SETTINGS_MODULE path in my python script, but how exactly would I do this?

  • 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-06-06T17:44:46+00:00Added an answer on June 6, 2026 at 5:44 pm

    Assuming your project settings are in /Users/david542/Desktop/project/my_settings.py you need to set DJANGO_SETTINGS_MODULE to ‘my_settings’ to let Django know where it is.

    To set the variable, just call your script using

    DJANGO_SETTINGS_MODULE=my_settings python /path/to/your/script.py
    

    Also, I would advise you not to hard-code the path to your project in your script but to pass it along using the PYTHONPATH environment variable, as follow:

    PYTHONPATH="/Users/david542/Desktop/project" DJANGO_SETTINGS_MODULE=my_settings python /path/to/your/script.py
    

    Cheers,

    Simon

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a python script that runs a loop in which it calls
I have a python script that runs on windows and uses win32 extensions and
I have a python script that runs a program, which generates few .exe files
I currently have a python script that runs every few minutes and picks up
I have a Python script that uses built-in modules but also imports a number
I have a python script that uses threads and makes lots of HTTP requests.
I have this bash script on the server that runs every hour, via cron.
I have a python script that runs a subprocess to get some data and
I have Jenkins running a python script that makes some SVN calls, my problem
I have an installation script written in Python (in Linux) that runs as root

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.