Permalink
Browse files

Better error if BeautifulSoup import fails

  • Loading branch information...
batterseapower committed Feb 11, 2010
1 parent d3559d1 commit 70ad3f15c40e161e38a505317ad83b44b548bdea
Showing with 8 additions and 1 deletion.
  1. +8 −1 pinyin/model.py
View
@@ -3,7 +3,6 @@
import htmlentitydefs
import re
-from BeautifulSoup import BeautifulSoup, Tag
import sqlalchemy
import unicodedata
@@ -332,6 +331,14 @@ def tokenizetext(text, forcenumeric):
"""
def tokenize(html, forcenumeric=False):
+ try:
+ from BeautifulSoup import BeautifulSoup, Tag
+ except ImportError, e:
+ if utils.islinux():
+ raise ImportError("Could not import the Beautiful Soup library! Since you are running on Linux, you may have to install it manually. Try running 'sudo apt-get install python-beautifulsoup' using the terminal.")
+ else:
+ raise e
+
def extract_attr_maybe(attrs, attr, into, extractor):
if attr not in attrs:
return {}

0 comments on commit 70ad3f1

Please sign in to comment.