Python AttributeError: 模块 'html.parser' 没有属性 'HTMLParseError'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34827566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AttributeError: module 'html.parser' has no attribute 'HTMLParseError'
提问by HyperZhang
- This is the hints,how can I resolve it?
- I use Python 3.5.1 created a virtual envirement by virtualenv
- The source code works well on my friend's computer machine
- 这是提示,我该如何解决?
- 我使用 Python 3.5.1 通过 virtualenv 创建了一个虚拟环境
- 源代码在我朋友的电脑上运行良好
Error:
错误:
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'
回答by ppalacios
I've just got the same error here. The Django version installed on my machine was 1.7.
我刚刚在这里遇到了同样的错误。我机器上安装的 Django 版本是 1.7。
Upgrading to Django 1.8.* solved the problem for me.
升级到 Django 1.8.* 为我解决了这个问题。
回答by mazulo
As you can read herethis error is raised...
because
HTMLParseError
is deprecated from Python 3.3 onwards and removed in Python 3.5.
因为
HTMLParseError
从 Python 3.3 开始不推荐使用并在 Python 3.5 中删除。
What you can do is downgrade your Python version or upgrade your Django version.
您可以做的是降级 Python 版本或升级 Django 版本。
回答by Kasramvd
You can upgrade your Django using following command:
您可以使用以下命令升级您的 Django:
If you are using pip3
:
如果您正在使用pip3
:
sudo pip3 install django --upgrade
If pip
:
如果pip
:
sudo pip install django --upgrade
回答by elhay efrat
pip install Django --upgrade
python manage.py runserver