2015-03-05 13 views
8

Code:ImportError: Kein Modul namens 'html.parser'; 'Html' ist kein Paket (python3)

from html.parser import HTMLParser 

Traceback (jüngste Aufforderung zuletzt):

File "program.py", line 7, in <module> 
    from html.parser import HTMLParser 
ImportError: No module named 'html.parser'; 'html' is not a package 

Ich nenne es mit python3 program.py

Python-Version: Python 3.4 .0

+0

drucken versuchen Sie die Installation von python-html5lib, die Ihr Problem möglicherweise lösen könnte. – Sagar

Antwort

10

Sie haben eine lokale Datei mit dem Namen html.py erstellt, die maskiert Das Standard-Bibliothekspaket.

Benennen Sie es um oder löschen Sie es; Sie können es mit lokalisieren:

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 
5

Sie haben eine Datei html.py (oder html.pyc) irgendwo in Ihrem 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 

einfach die Datei umbenennen (auf myhtml.py). Wenn Sie sich nicht sicher sind, wo es sich befindet, können Sie den Standort mit

# Insert temporarily before the problematic line 
import html 
print(html.__file__)