Django ImportError: No module named formtools.wizard.storage 报错解决方案

欢迎大家扫码关注我的微信公众号:
数据之恋

一、 问题描述

当我通过命令行运行 Django 项目服务的时候, 报出如下错误:

root@ubuntu:~/workspace/001-django_xadmin/xadmin-master/demo_app# python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x7fdd525f7230>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 116, in populate
    app_config.ready()
  File "/home/cybeyond/workspace/001-django_xadmin/xadmin-master/demo_app/../xadmin/apps.py", line 14, in ready
    self.module.autodiscover()
  File "/home/cybeyond/workspace/001-django_xadmin/xadmin-master/demo_app/../xadmin/__init__.py", line 49, in autodiscover
    register_builtin_plugins(site)
  File "/home/cybeyond/workspace/001-django_xadmin/xadmin-master/demo_app/../xadmin/plugins/__init__.py", line 41, in register_builtin_plugins
    [import_module('xadmin.plugins.%s' % plugin) for plugin in PLUGINS if plugin not in exclude_plugins]
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/cybeyond/workspace/001-django_xadmin/xadmin-master/demo_app/../xadmin/plugins/wizard.py", line 12, in <module>
    from django.contrib.formtools.wizard.storage import get_storage
ImportError: No module named formtools.wizard.storage

二、 使用环境

我的环境是:
Ubuntu 16.04 + python2.7.6 + Django 1.11.6

三、 解决方案

解决方案很简单, 卸载 formtools, 然后重新安装:
首先卸载:

root@ubuntu:~/workspace/001-django_xadmin/xadmin-master/demo_app# pip uninstall django-formtools
The directory '/home/cybeyond/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling django-formtools-1.0:
  Would remove:
    /usr/local/lib/python2.7/dist-packages/django_formtools-1.0.dist-info/*
    /usr/local/lib/python2.7/dist-packages/formtools/*
Proceed (y/n)? y
  Successfully uninstalled django-formtools-1.0

然后重新安装:

root@ubuntu:~/workspace/001-django_xadmin/xadmin-master/demo_app# pip install django-formtools
The directory '/home/cybeyond/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/cybeyond/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting django-formtools
  Downloading https://files.pythonhosted.org/packages/97/3f/b8e04c41c028d5cdad651393abea1f686d846c717d8ab5d5ebe2974f711c/django_formtools-2.1-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 133kB 644kB/s 
Requirement already satisfied: Django>=1.8 in /usr/local/lib/python2.7/dist-packages (from django-formtools) (1.11.6)
Requirement already satisfied: pytz in /usr/local/lib/python2.7/dist-packages (from Django>=1.8->django-formtools) (2018.7)
Installing collected packages: django-formtools
Successfully installed django-formtools-2.1

最后, 使用命令行运行 Django 服务:

root@ubuntu:~/workspace/001-django_xadmin/xadmin-master/demo_app# python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 20 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, app, auth, contenttypes, reversion, sessions, xadmin.
Run 'python manage.py migrate' to apply them.

December 29, 2018 - 03:50:17
Django version 1.11.6, using settings 'demo.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

可以发现, 错误信息没有再被报出, Django 服务也运行起来了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值