Frage

Disclaimer: I am new to python and django but have Drupal programming experience. I'm using Windows 7 (same issues on Windows XP)

On python 2.7 and Django-1.3.1, I successfully created a default project

django-admin.py startproject djsite

Now, I need to "bootstrap" djsite.manage as explained here (http://www.pyinstaller.org/wiki/Recipe/DjangoApplication) in a file called bootstrap.py located in djsite's parent directory as follows:

import djsite.manage
djsite.manage.execute_manager(djsite.manage.settings,['manage.py', 'runserver'])

Yet, as soon as the compiler sees:

import djsite.manage

I get this: "Error: Can't find the file 'settings.py' in the directory containing 'C:\Python27\Lib\site-packages\djsite\manage.pyc'. It appears you've customized things... You'll have to run django-admin.py, passing it your settings module." And, I don't know how to follow the error's advice in this situation.

However, if I instead issue the following in bootstrap.py:

import os, sys
sys.path.append(os.path.abspath('djsite'))
import djsite.manage
djsite.manage.execute_manager(djsite.manage.settings,['manage.py', 'runserver'])

the script works correctly, but it breaks Pyinstaller (I've already asked this question on that software's mailing list (http://groups.google.com/group/pyinstaller/browse_thread/thread/174a72e26c26a44c). Even if I add the path to the djsite in my PATH variable, I get the same error.

So my question here is this: Why does importing the manage.py module fail with this approach and how can I proceed? Thanks!

War es hilfreich?

Lösung

Try adding this to your bootstrap.py to inform it where your settings file lives:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'djsite.settings'

This will assume that djsite is in your pythonpath. That is, if its located here: /path/to/my/djsite, then this should be in your pythonpath: /path/to/my

Actually the best way to be doing this from the start is to being using virtualenv which will ensure that your environment is correct. I feel like that had to have been part of your tutorial if I remember bootstrap at all. If you are using virtualenv, make sure you remembered to source bin/activate

If that doesn't work, you can try altering the runserver command:

args = ['manage.py', 'runserver', '--settings=/path/to/my/djsite/settings.py']
djsite.manage.execute_manager(djsite.manage.settings, args)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top