WebFaction
Community site: login faq

I'm trying to run a standalone django script inside a django app directory. In order for the script to work with django I started it with the following code:

import sys,os
sys.path.append(os.path.dirname(os.path.dirname(os.getcwdu())))
os.environ['DJANGO_SETTINGS_MODULE']='myproject.settings'
from django.core.management import setup_environ
from myproject import settings
setup_environ(settings)

Even if this is the only code in the file, I keep receiving the following error:

Traceback (most recent call last):
  File "generate_graphs.py", line 4, in ?
    from django.core.management import setup_environ
ImportError: No module named django.core.management

I also tried writing this code in python's shell and received:

[myusername@webXXX myapp]$ python
Python 2.4.3 (#1, Nov 11 2010, 13:34:43)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys,os
>>> sys.path.append(os.path.dirname(os.path.dirname(os.getcwdu())))
>>> os.environ['DJANGO_SETTINGS_MODULE']='myproject.settings'
>>> from django.core.management import setup_environ
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named django.core.management
>>>

asked 07 Feb '11, 11:45

Jonathan
281813
accept rate: 0%


Notice you're using Python 2.4.3 by default. Try the following:

python2.6 your_script.py
permanent link

answered 07 Feb '11, 11:46

Jonathan
281813
accept rate: 0%

Yes, that's why you were having the problem. You can change your default python version by following the documentation here:

http://docs.webfaction.com/software/python.html#choosing-a-default-python-version

(07 Feb '11, 13:28) aaronh ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×25

question asked: 07 Feb '11, 11:45

question was seen: 4,989 times

last updated: 07 Feb '11, 13:28

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM