简体   繁体   中英

Can't launch shell with Django's manage.py utility

I am following along this Django tutorial and have just arrived at "Playing with the API" section which requires launching the python interactive shell via a utility which automatically sets up environmental variables. Upon running >>>python manage.py shell I get:

C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\db\backends\sqlite3\base.py:63: RuntimeWarning: SQLite received a naive datetime (2015-02-25 22:41:12.086961) while time zone support is active.
  RuntimeWarning)

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\base.py", line 533, in handle
    return self.handle_noargs(**options)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\commands\shell.py", line 77, in handle_noargs
    self.run_shell(shell=interface)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\commands\shell.py", line 62, in run_shell
    return getattr(self, shell)()
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\commands\shell.py", line 45, in ipython
    ip()
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\django\core\management\commands\shell.py", line 39, in _ipython
    start_ipython(argv=[])
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\__init__.py", line 120, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\config\application.py", line 563, in launch_instance
    app.initialize(argv)
  File "<string>", line 2, in initialize
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\config\application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\terminal\ipapp.py", line 332, in initialize
    self.init_shell()
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\terminal\ipapp.py", line 348, in init_shell
    ipython_dir=self.ipython_dir, user_ns=self.user_ns)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\config\configurable.py", line 354, in instance
    inst = cls(*args, **kwargs)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\terminal\interactiveshell.py", line 328, in __init__
    **kwargs
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\core\interactiveshell.py", line 465, in __init__
    self.init_history()
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\core\interactiveshell.py", line 1521, in init_history
    self.history_manager = HistoryManager(shell=self, parent=self)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\core\history.py", line 498, in __init__
    self.new_session()
  File "<string>", line 2, in new_session
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\core\history.py", line 68, in needs_sqlite
    return f(self, *a, **kw)
  File "C:\Users\datumZ\Anaconda\envs\myThai\lib\site-packages\IPython\core\history.py", line 516, in new_session
    NULL, "") """, (datetime.datetime.now(),))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    c.Application.verbose_crash=True

I have tried bypassing the manage.py utility by setting the DJANGO_SETTINGS_MODULE directly and various other things, but I would prefer to follow the tutorial as directed since I am using the correct versions of python and Django. Any help on solving the interface error shown above is appreciated.

Update your sqlite3 library and you should be good. It looks like your version does not have support for converting datetime objects. You can test this by executing the following on the shell:

Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> import datetime
>>> db = sqlite3.connect('/tmp/sql.sqlite3')
>>> db.execute("""CREATE TABLE IF NOT EXISTS sessions (session integer
...                         primary key autoincrement, start timestamp,
...                         end timestamp, num_cmds integer, remark text)""")
>>> db.commit()
>>> cur = db.execute("""INSERT INTO sessions VALUES (NULL, ?, NULL,NULL, "") """, (datetime.datetime.now(),))
>>> cur.fetchall()
[]
>>> db.execute("""SELECT * FROM sessions""").fetchall()
[(1, u'2015-02-25 22:07:00.284058', None, None, u'')]

pip install -U sqlite3

This is what worked for me:

Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
>>> sqlite3.version
'2.6.0'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM