[英]ImportError: No module named 'html.parser'; 'html' is not a package (python3)
Code: 码:
from html.parser import HTMLParser
Traceback (most recent call last): Traceback(最近一次调用最后一次):
File "program.py", line 7, in <module>
from html.parser import HTMLParser
ImportError: No module named 'html.parser'; 'html' is not a package
I call it with python3 program.py
我用
python3 program.py
调用它
Python version: Python 3.4.0 Python版本:Python 3.4.0
You have created a local file named html.py
that masks the standard library package. 您已创建一个名为
html.py
的本地文件,该文件掩盖了标准库包。
Rename it or delete it; 重命名或删除它; you can locate it with:
你可以找到它:
python3 -c "import html; print(html.__file__)"
Demo: 演示:
naga:stackoverflow-3.4 mpieters$ touch html.py
naga:stackoverflow-3.4 mpieters$ bin/python -c 'from html.parser import HTMLParser'
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'html.parser'; 'html' is not a package
naga:stackoverflow-3.4 mpieters$ bin/python -c "import html; print(html.__file__)"
/.../stackoverflow-3.4/html.py
naga:stackoverflow-3.4 mpieters$ rm html.py
naga:stackoverflow-3.4 mpieters$ bin/python -c 'from html.parser import HTMLParser; print("Succeeded")'
Succeeded
You have a file html.py
(or html.pyc
) somewhere in your Python path : 你的Python路径中有一个文件
html.py
(或html.pyc
):
$ touch html.py
$ python3 -c 'import html.parser'
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'html.parser'; 'html' is not a package
Simply rename the file (to myhtml.py
). 只需重命名文件(到
myhtml.py
)。 If you are unsure where it is, you can print its location with 如果您不确定它在哪里,您可以打印它的位置
# Insert temporarily before the problematic line
import html
print(html.__file__)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.