Question

I am trying to use the Django 1.61 shell with python3.3 in Aptana 3.4 and immediately upon launch an error occurs and I am unable to import from my own project.

Here is how the Django shell looks like:

import sys; print('%s %s' % (sys.executable or sys.platform, sys.version)) /Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]

from django.core import management;import testDjango.settings as settings;management.setup_environ(settings)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setup_environ'
from testApp.models import Poll
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/gideonnbar/Desktop/dev_python/aptana_workspace/testDjango/src/testApp/models.py", line 1, in <module>
    from django.db import models
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/db/models/__init__.py", line 5, in <module>
    from django.db.models.query import Q
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/db/models/query.py", line 17, in <module>
    from django.db.models.deletion import Collector
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/db/models/deletion.py", line 4, in <module>
    from django.db.models import signals, sql
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/db/models/sql/__init__.py", line 4, in <module>
    from django.db.models.sql.subqueries import *
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/db/models/sql/subqueries.py", line 12, in <module>
    from django.db.models.sql.query import Query
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/db/models/sql/query.py", line 22, in <module>
    from django.db.models.sql import aggregates as base_aggregates_module
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/db/models/sql/aggregates.py", line 9, in <module>
    ordinal_aggregate_field = IntegerField()
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/db/models/fields/__init__.py", line 116, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/conf/__init__.py", line 49, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/gideonnbar/Desktop/dev_python/Django-1.6.1/django/conf/__init__.py", line 132, in __init__
    % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'mysite'
Était-ce utile?

La solution 3

I think the problem has to do with the Aptana 3.4.2 IDE since I opened a shell in the command line and managed to import and use my app models.

Here is how I did it:

cd directory_where_manage.py_resides

python3.3 manage.py shell

Autres conseils

Workaround: instead of using "Django->Shell with django environment" use "Custom command->" to start the shell.

Since Django 1.4, setup_environ is deprecated, and since Django 1.6, it is removed (see the release process for details). A possible replacement is setting the DJANGO_SETTINGS_MODULE environment variable, and I guess that's where mysite.settings is coming from. I'm not using Aptana, so I can't help you with that part.

I solved my problem by placing an empty __init__.py file in the sub directory.

In your case check if the mysite/ directory (which contains the settings.py file) is missing an init file.

Go to Window Menu -> Preferences -> Pydev -> "Interactive Console" -> "Initial interpreter commands" add the following:

from django.conf import settings 
settings.configure()

Credit to the comment in this website :

http://zhangyelei.blogspot.com.es/2013/12/pydev-defect-with-django-16.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top