Code:
from html.parser import HTMLParser
Traceback (most recent call last):
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
Python version: Python 3.4.0
You have created a local file named html.py
that masks the standard library package.
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:
$ 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
). If you are unsure where it is, you can print its location with
# Insert temporarily before the problematic line
import html
print(html.__file__)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With