BS4 import error _htmlparser on Ubuntu 10.04

992 views
Skip to first unread message

Ghost of Kendo

unread,
Mar 30, 2012, 5:23:45 AM3/30/12
to beautifulsoup
Hello,

I made a Python 3 script using BeautifulSoup 4 (4.0.2 exactly) and it
works very well on my main system (Debian 6 and Python 3.1.3).
But when I tried to run it on another system (Ubuntu 10.04.2 and
Python 3.1.2), I suddenly got the following error:
"Traceback (most recent call last):
File "./friends_distance.py", line 28, in <module>
from bs4 import BeautifulSoup
File "/usr/local/lib/python3.1/dist-packages/bs4/__init__.py", line
29, in <module>
from .builder import builder_registry
File "/usr/local/lib/python3.1/dist-packages/bs4/builder/
__init__.py", line 279, in <module>
from ..import _htmlparser
ImportError: cannot import name _htmlparser"

Since I installed BS4 the same way on the two systems (using 'python3
setup.py install' and it successfully completed each time), the only
thing I could think of was to try to install lxml (I usually stick to
Python's default parser) to see if it would solve this _htmlparser
error. It eventually did not change anything.

I am sure the solution is not complicated but I ran out of ideas so I
would greatly appreciate any hint on solving this error.

Thanks in advance.

Leonard Richardson

unread,
Mar 30, 2012, 8:30:27 AM3/30/12
to beauti...@googlegroups.com
>  File "/usr/local/lib/python3.1/dist-packages/bs4/builder/
> __init__.py", line 279, in <module>
>    from ..import _htmlparser
> ImportError: cannot import name _htmlparser"

The problem probably happened during installation. Beautiful Soup is
distributed as Python 2 code, and a Python 3 system is responsible for
converting it to Python 3 code upon installation.

In this case, the original line was:

from .import _htmlparser

And the second period was probably erroneously added during Python 3
conversion. It's possible that some versions of the conversion script
will make this mistake and some will not.

There should be a space between "." and "import", which I've added.
Try this line and see if it works for you:

from . import _htmlparser

Leonard

Ghost of Kendo

unread,
Mar 30, 2012, 9:35:40 AM3/30/12
to beautifulsoup
It worked like a charm.

Thank you very much for your help and your explanations.
Reply all
Reply to author
Forward
0 new messages