我正在跟随this Django教程,刚刚到达"玩API"需要通过自动设置环境变量的实用程序启动python交互式shell的部分。运行>>>python manage.py shell
后,我得到:
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
我尝试通过直接设置DJANGO_SETTINGS_MODULE以及其他各种方法来绕过manage.py实用程序,但我更喜欢按照指示操作,因为我使用的是正确版本的python和Django。任何有关解决上面显示的界面错误的帮助都表示赞赏。
答案 0 :(得分:1)
更新你的sqlite3库,你应该很好。看起来您的版本不支持转换日期时间对象。您可以通过在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
这对我有用:
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'