Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango and ipython - __import__() argument 1 must be string, not DictConfigurator
    primarykey
    data
    text
    <p>My purpose is being able to startup a python shell (ipython, bpython or simple python) and:</p> <ol> <li>autosetup settings.py</li> <li>autoload the models from INSTALLED_APPS</li> <li>I know of ./manage.py shell and django.extensions, but I'd like to choose what shell to run on a whim.</li> </ol> <p>To this end, I have stuck this code (from <a href="http://agiliq.com/blog/2009/12/using-bpython-shell-with-django-and-some-ipython-f/" rel="nofollow">http://agiliq.com/blog/2009/12/using-bpython-shell-with-django-and-some-ipython-f/</a>) in my PYTHONSTARTUP:</p> <pre><code>try: from django.core.management import setup_environ import settings setup_environ(settings) print 'imported django settings' try: exec_strs = ["from %s.models import *"%apps for apps in settings.INSTALLED_APPS ] for x in exec_strs: try: exec(x) except Exception,e: print 'Not imported for %s' %x print "Exception:%s" %repr(e) print 'imported django models' except: pass except: pass </code></pre> <p>This works OK in bpyton/python. Ipython ignores it, so I customised ipy_user_conf.py to load it:</p> <pre><code>import os try: if os.environ.get("PYTHONSTARTUP",None) is not None: execfile(os.environ.get("PYTHONSTARTUP")) except: pass </code></pre> <p>This fails, however, and appears to permanently break ipython's import, with the puzzling diagnostic:</p> <pre><code>Not imported for from tick.et.models import * Exception:ValueError("Unable to configure handler 'mail_admins': __import__() argument 1 must be string, not DictConfigurator",) </code></pre> <p>Googling reveals the issue to be connected with the way Django uses the logging facility, the details being way beyond my comprehension. But note that manage.py shell uses python just fine without the above mentioned problem. The question thus becomes, what am I doing wrong?</p> <p><em><strong>Later</em></strong></p> <p>After some digging and careful reading of <a href="http://bugs.python.org/issue12718" rel="nofollow">http://bugs.python.org/issue12718</a> - it appears the issue is caused by a bug of winpdb/rpdb2 (installed on my box) incorrectly wrapping python's builtin import. I suppose django overrides import as well, and that's why manage.py escapes this particular snag. I am still curious to know if an external fix exists (short of patching rpdb2, that is). </p> <p><em><strong>Later Still</em></strong></p> <p>I reported the issue as a bug on winpdb's site. <strong>Not</strong> closing the question, because none of the reasons available appear to apply.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload