error executing "import html.parser" from a script

Paul Volkov capt-obvious at yandex.ru
Fri Oct 19 05:15:45 EDT 2012


What is this madness?
I have Python 3.3.0 installed on Windows XP. I do not have Python 2
(but I had it before). I do the following steps:

1. Import from an interactive session (no problems)

>python
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import html
>>> import html.parser
>>> ^Z

2. Import from command line (no problems)

>python -c "import html.parser"

3. Import from a script. The script contains only one import line.
Everything else is commented out.

>python e:\tmp\pyt\html.py
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1512, 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 "e:\tmp\pyt\html.py", line 7, in <module>
    import html.parser
  File "e:\tmp\pyt\html.py", line 7, in <module>
    import html.parser
ImportError: No module named 'html.parser'; html is not a package

4. And then I tried to print sys.path from my script by modifying it this way:
import sys
print (sys.path)
import html.parser

And the result is: (I don't know why sys.path is printed twice)

>python e:\tmp\pyt/html.py
['e:\\tmp\\pyt', 'D:\\WINDOWS\\system32\\python33.zip',
'D:\\Python33\\DLLs', 'D:\\Python33\\lib', '
D:\\Python33', 'D:\\Python33\\lib\\site-packages']
['e:\\tmp\\pyt', 'D:\\WINDOWS\\system32\\python33.zip',
'D:\\Python33\\DLLs', 'D:\\Python33\\lib', '
D:\\Python33', 'D:\\Python33\\lib\\site-packages']
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1512, 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 "e:\tmp\pyt/html.py", line 8, in <module>
    import html.parser
  File "e:\tmp\pyt\html.py", line 8, in <module>
    import html.parser
ImportError: No module named 'html.parser'; html is not a package



More information about the Python-list mailing list