【问题标题】:AttributeError: module 'html.parser' has no attribute 'HTMLParseError'AttributeError:模块“html.parser”没有属性“HTMLParseError”
【发布时间】:2016-04-22 00:29:54
【问题描述】:
  1. 这是提示,我该如何解决?
  2. 我使用 Python 3.5.1 通过 virtualenv 创建了一个虚拟环境
  3. 源代码在我朋友的电脑上运行良好

错误:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "A:\Python3.5\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "A:\Python3.5\lib\site-packages\django\core\management\__init__.py", line 354, in execute
    django.setup()
  File "A:\Python3.5\lib\site-packages\django\__init__.py", line 18, in setup
    from django.utils.log import configure_logging
  File "A:\Python3.5\lib\site-packages\django\utils\log.py", line 13, in <module>
    from django.views.debug import ExceptionReporter, get_exception_reporter_filter
  File "A:\Python3.5\lib\site-packages\django\views\debug.py", line 10, in <module>
    from django.http import (HttpResponse, HttpResponseServerError,
  File "A:\Python3.5\lib\site-packages\django\http\__init__.py", line 4, in <module>
    from django.http.response import (
  File "A:\Python3.5\lib\site-packages\django\http\response.py", line 13, in <module>
    from django.core.serializers.json import DjangoJSONEncoder
  File "A:\Python3.5\lib\site-packages\django\core\serializers\__init__.py", line 23, in <module>
    from django.core.serializers.base import SerializerDoesNotExist
  File "A:\Python3.5\lib\site-packages\django\core\serializers\base.py", line 6, in <module>
    from django.db import models
  File "A:\Python3.5\lib\site-packages\django\db\models\__init__.py", line 6, in <module>
    from django.db.models.query import Q, QuerySet, Prefetch  # NOQA
  File "A:\Python3.5\lib\site-packages\django\db\models\query.py", line 13, in <module>
    from django.db.models.fields import AutoField, Empty
  File "A:\Python3.5\lib\site-packages\django\db\models\fields\__init__.py", line 18, in <module>
    from django import forms
  File "A:\Python3.5\lib\site-packages\django\forms\__init__.py", line 6, in <module>
    from django.forms.fields import *  # NOQA
  File "A:\Python3.5\lib\site-packages\django\forms\fields.py", line 18, in <module>
    from django.forms.utils import from_current_timezone, to_current_timezone
  File "A:\Python3.5\lib\site-packages\django\forms\utils.py", line 15, in <module>
    from django.utils.html import format_html, format_html_join, escape
  File "A:\Python3.5\lib\site-packages\django\utils\html.py", line 16, in <module>
    from .html_parser import HTMLParser, HTMLParseError
  File "A:\Python3.5\lib\site-packages\django\utils\html_parser.py", line 12, in <module>
    HTMLParseError = _html_parser.HTMLParseError
AttributeError: module 'html.parser' has no attribute 'HTMLParseError'

【问题讨论】:

  • 你朋友用的版本和你一样吗?
  • 搜索那个错误信息会得到很多结果,你真的做过研究吗?
  • 你使用的是什么版本的 Django?
  • 我的django版本是1.8.7,我是通过vituralenv和requirement.txt安装的。所以他的virsion和我的一样。

标签: python django python-3.x


【解决方案1】:
pip install Django --upgrade
python manage.py runserver

【讨论】:

  • 请编辑您的答案以包含一些关于这如何准确回答问题的信息。这将使您的问题对原始提问者和将来的任何人都更容易理解和有用。谢谢。
【解决方案2】:

您可以使用以下命令升级您的 Django:

如果您使用的是pip3:

sudo pip3 install django --upgrade

如果pip:

sudo pip install django --upgrade

【讨论】:

    【解决方案3】:

    如您所见,here 引发了此错误...

    因为HTMLParseError 从 Python 3.3 开始已被弃用,并在 Python 3.5 中被删除。

    您可以做的是降级您的 Python 版本或升级您的 Django 版本。

    【讨论】:

    • “这里”链接不再可用。
    • pip install Django --upgrade
    【解决方案4】:

    我在这里遇到了同样的错误。我机器上安装的Django版本是1.7。

    升级到 Django 1.8.* 为我解决了这个问题。

    【讨论】:

    • 我的 django 版本是 1.8.7.,我是通过 vituralenv 和requirement.txt 安装的。
    • 阅读您的回溯,您看起来并没有使用 virtualenv 运行您的项目。你确定它被激活了吗?
    • 我遵循的教程安装了 1.7.1 版,我遇到了同样的问题。您建议升级到 1.8.8 解决了我遇到的问题,谢谢!
    • @heavyweight 现在不要使用 1.8.8,因为在 1.8 系列中进行了许多更新,包括安全补丁。今天的最后一个版本是 1.8.13 ;)
    猜你喜欢
    • 2018-04-14
    • 2019-02-18
    • 1970-01-01
    • 2020-01-01
    • 2019-07-20
    • 2021-11-05
    • 2021-11-04
    • 2021-02-23
    相关资源
    最近更新 更多