Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Running syncdb from an install script in django_project/install [RSS Feed]

#1 June 11, 2010 14:11:59

S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Running syncdb from an install script in django_project/install


I'm writing an install script that resides in django_project/install
and one of things it does, is programmatically run syncdb. My current
code for this is correct if I do:

cd ..
python
import os
os.environ="settings"
from django.core.management import call_command
call_command('syncdb', interactive=False)

If I copy this code into my installer, or indeed do the same as above,
but inside the django_project/install directory it fails:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/django/core/management/
__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/usr/lib/python2.6/site-packages/django/core/management/
base.py", line 221, in execute
self.validate()
File "/usr/lib/python2.6/site-packages/django/core/management/
base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.6/site-packages/django/core/management/
validation.py", line 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
line 145, in get_app_errors
self._populate()
File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
line 60, in _populate
self.load_app(app_name, True)
File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
line 82, in load_app
if not module_has_submodule(app_module, 'models'):
File "/usr/lib/python2.6/site-packages/django/utils/
module_loading.py", line 14, in module_has_submodule
for entry in package.__path__: # No __path__, then not a package.
AttributeError: 'module' object has no attribute '__path__'

I've tried adding the project's path to sys.path, but that doesn't
make a difference. Is there a way to do this from a sub-directory?
Thanks

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 11, 2010 16:16:11

Euan G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Running syncdb from an install script in django_project/install


This sounds like a path type issue and these sorts of things are a
PITA to sort out. Have you tried setting the settings path a bit more
explitly:

os.environ="django_project.settings"

I had some trouble with kind of thing in a project I was working on
(https://launchpad.net/django-audit/). I wrote a test suite which
needed a fake Django app to test a load of things and I had to use the
full path to the settings file:

os.environ =
"tests.fixtures.sampledjango.settings"

Are you installing the application using setuptools? If not and you
can't put it in the site-packages, I'd consider using a virtualenv.

Euan

On Jun 11, 2:11 pm, Stodge <sto...@gmail.com> wrote:
> I'm writing an install script that resides in django_project/install
> and one of things it does, is programmatically run syncdb. My current
> code for this is correct if I do:
>
> cd ..
> python
> import os
> os.environ="settings"
> from django.core.management import call_command
> call_command('syncdb', interactive=False)
>
> If I copy this code into my installer, or indeed do the same as above,
> but inside the django_project/install directory it fails:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib/python2.6/site-packages/django/core/management/
> __init__.py", line 166, in call_command
>     return klass.execute(*args, **defaults)
>   File "/usr/lib/python2.6/site-packages/django/core/management/
> base.py", line 221, in execute
>     self.validate()
>   File "/usr/lib/python2.6/site-packages/django/core/management/
> base.py", line 249, in validate
>     num_errors = get_validation_errors(s, app)
>   File "/usr/lib/python2.6/site-packages/django/core/management/
> validation.py", line 28, in get_validation_errors
>     for (app_name, error) in get_app_errors().items():
>   File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> line 145, in get_app_errors
>     self._populate()
>   File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> line 60, in _populate
>     self.load_app(app_name, True)
>   File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> line 82, in load_app
>     if not module_has_submodule(app_module, 'models'):
>   File "/usr/lib/python2.6/site-packages/django/utils/
> module_loading.py", line 14, in module_has_submodule
>     for entry in package.__path__:  # No __path__, then not a package.
> AttributeError: 'module' object has no attribute '__path__'
>
> I've tried adding the project's path to sys.path, but that doesn't
> make a difference. Is there a way to do this from a sub-directory?
> Thanks

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 11, 2010 16:27:30

S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Running syncdb from an install script in django_project/install


Good point. I tried adding the Django project's path to sys.path and
tried your suggestions for the settings, but it still gives me the
same error. Thanks

# Add the Django project path to sys.path.
sys.path.append(config.INSTALL_DIR)

# Add the parent path too.
parent_path = os.path.split(config.INSTALL_DIR)
sys.path.append(parent_path)

# Run syncdb.
os.environ="settings" # or
project.settings
import settings
from django.core.management.commands import syncdb
syncdb.Command().execute(noinput=True)

On Jun 11, 11:16 am, Euan Goddard <euan.godd...@2degreesnetwork.com>
wrote:
> This sounds like a path type issue and these sorts of things are a
> PITA to sort out. Have you tried setting the settings path a bit more
> explitly:
>
> os.environ="django_project.settings"
>
> I had some trouble with kind of thing in a project I was working on
> (https://launchpad.net/django-audit/). I wrote a test suite which
> needed a fake Django app to test a load of things and I had to use the
> full path to the settings file:
>
> os.environ =
> "tests.fixtures.sampledjango.settings"
>
> Are you installing the application using setuptools? If not and you
> can't put it in the site-packages, I'd consider using a virtualenv.
>
> Euan
>
> On Jun 11, 2:11 pm, Stodge <sto...@gmail.com> wrote:
>
> > I'm writing an install script that resides in django_project/install
> > and one of things it does, is programmatically run syncdb. My current
> > code for this is correct if I do:
>
> > cd ..
> > python
> > import os
> > os.environ="settings"
> > from django.core.management import call_command
> > call_command('syncdb', interactive=False)
>
> > If I copy this code into my installer, or indeed do the same as above,
> > but inside the django_project/install directory it fails:
>
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> >   File "/usr/lib/python2.6/site-packages/django/core/management/
> > __init__.py", line 166, in call_command
> >     return klass.execute(*args, **defaults)
> >   File "/usr/lib/python2.6/site-packages/django/core/management/
> > base.py", line 221, in execute
> >     self.validate()
> >   File "/usr/lib/python2.6/site-packages/django/core/management/
> > base.py", line 249, in validate
> >     num_errors = get_validation_errors(s, app)
> >   File "/usr/lib/python2.6/site-packages/django/core/management/
> > validation.py", line 28, in get_validation_errors
> >     for (app_name, error) in get_app_errors().items():
> >   File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> > line 145, in get_app_errors
> >     self._populate()
> >   File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> > line 60, in _populate
> >     self.load_app(app_name, True)
> >   File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> > line 82, in load_app
> >     if not module_has_submodule(app_module, 'models'):
> >   File "/usr/lib/python2.6/site-packages/django/utils/
> > module_loading.py", line 14, in module_has_submodule
> >     for entry in package.__path__:  # No __path__, then not a package.
> > AttributeError: 'module' object has no attribute '__path__'
>
> > I've tried adding the project's path to sys.path, but that doesn't
> > make a difference. Is there a way to do this from a sub-directory?
> > Thanks

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 June 11, 2010 16:37:18

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Running syncdb from an install script in django_project/install


On Fri, Jun 11, 2010 at 9:11 AM, Stodge <sto...@gmail.com> wrote:

> I'm writing an install script that resides in django_project/install
> and one of things it does, is programmatically run syncdb. My current
> code for this is correct if I do:
>
> cd ..
> python
> import os
> os.environ="settings"
> from django.core.management import call_command
> call_command('syncdb', interactive=False)
>
> If I copy this code into my installer, or indeed do the same as above,
> but inside the django_project/install directory it fails:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/python2.6/site-packages/django/core/management/
> __init__.py", line 166, in call_command
> return klass.execute(*args, **defaults)
> File "/usr/lib/python2.6/site-packages/django/core/management/
> base.py", line 221, in execute
> self.validate()
> File "/usr/lib/python2.6/site-packages/django/core/management/
> base.py", line 249, in validate
> num_errors = get_validation_errors(s, app)
> File "/usr/lib/python2.6/site-packages/django/core/management/
> validation.py", line 28, in get_validation_errors
> for (app_name, error) in get_app_errors().items():
> File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> line 145, in get_app_errors
> self._populate()
> File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> line 60, in _populate
> self.load_app(app_name, True)
> File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> line 82, in load_app
> if not module_has_submodule(app_module, 'models'):
> File "/usr/lib/python2.6/site-packages/django/utils/
> module_loading.py", line 14, in module_has_submodule
> for entry in package.__path__: # No __path__, then not a package.
> AttributeError: 'module' object has no attribute '__path__'
>
> I've tried adding the project's path to sys.path, but that doesn't
> make a difference. Is there a way to do this from a sub-directory?
>


You need to ensure the python path in effect when this code runs from your
installer is correct. Based on the error, it does not appear to be. The
error implies that something listed in INSTALLED_APPS is being found, but it
is not a package. Apparently what is being found when you run the code from
the shell is different from what is being found when you run the code in the
installer, and the likely cause of the difference is a different Python
path.

The first item in your PYTHONPATH will be the current directory. Is there
some .py file in your install directory that matches the name of an app you
have listed in installed apps? That could lead to this problem, if your
installer code is running with a current directory of your install
directory.

Note there is a ticket open on this error situation (http://code.djangoproject.com/ticket/13603). In older versions of Django
this oddity of having a non-package listed in INSTALLED_APPS was just
ignored. In your case I doubt the "fix" of simply ignoring whatever app is
causing the problem would likely not be helpful, since I'm guessing some
tables your installer should create would not be created. However the error
message could be more helpful.

Karen
--http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 June 11, 2010 18:18:03

S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Running syncdb from an install script in django_project/install


"Is there some .py file in your install directory that matches the
name of an app you have listed in installed apps?"

I think this was the problem. Thanks!!

On Jun 11, 11:37 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Fri, Jun 11, 2010 at 9:11 AM, Stodge <sto...@gmail.com> wrote:
> > I'm writing an install script that resides in django_project/install
> > and one of things it does, is programmatically run syncdb. My current
> > code for this is correct if I do:
>
> > cd ..
> > python
> > import os
> > os.environ="settings"
> > from django.core.management import call_command
> > call_command('syncdb', interactive=False)
>
> > If I copy this code into my installer, or indeed do the same as above,
> > but inside the django_project/install directory it fails:
>
> > Traceback (most recent call last):
> >  File "<stdin>", line 1, in <module>
> >  File "/usr/lib/python2.6/site-packages/django/core/management/
> > __init__.py", line 166, in call_command
> >    return klass.execute(*args, **defaults)
> >  File "/usr/lib/python2.6/site-packages/django/core/management/
> > base.py", line 221, in execute
> >    self.validate()
> >  File "/usr/lib/python2.6/site-packages/django/core/management/
> > base.py", line 249, in validate
> >    num_errors = get_validation_errors(s, app)
> >  File "/usr/lib/python2.6/site-packages/django/core/management/
> > validation.py", line 28, in get_validation_errors
> >    for (app_name, error) in get_app_errors().items():
> >  File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> > line 145, in get_app_errors
> >    self._populate()
> >  File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> > line 60, in _populate
> >    self.load_app(app_name, True)
> >  File "/usr/lib/python2.6/site-packages/django/db/models/loading.py",
> > line 82, in load_app
> >    if not module_has_submodule(app_module, 'models'):
> >  File "/usr/lib/python2.6/site-packages/django/utils/
> > module_loading.py", line 14, in module_has_submodule
> >    for entry in package.__path__:  # No __path__, then not a package.
> > AttributeError: 'module' object has no attribute '__path__'
>
> > I've tried adding the project's path to sys.path, but that doesn't
> > make a difference. Is there a way to do this from a sub-directory?
>
> You need to ensure the python path in effect when this code runs from your
> installer is correct. Based on the error, it does not appear to be. The
> error implies that something listed in INSTALLED_APPS is being found, but it
> is not a package. Apparently what is being found when you run the code from
> the shell is different from what is being found when you run the code in the
> installer, and the likely cause of the difference is a different Python
> path.
>
> The first item in your PYTHONPATH will be the current directory. Is there
> some .py file in your install directory that matches the name of an app you
> have listed in installed apps? That could lead to this problem, if your
> installer code is running with a current directory of your install
> directory.
>
> Note there is a ticket open on this error situation
> (http://code.djangoproject.com/ticket/13603). In older versions of Django
> this oddity of having a non-package listed in INSTALLED_APPS was just
> ignored. In your case I doubt the "fix" of simply ignoring whatever app is
> causing the problem would likely not be helpful, since I'm guessing some
> tables your installer should create would not be created. However the error
> message could be more helpful.
>
> Karen
> --http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Running syncdb from an install script in django_project/install [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support