使用'导入bs4'或从bs4导入时出现以下错误:BeautifulSoup'

时间:2014-10-20 14:42:28

标签: python beautifulsoup

使用import bs4from bs4 import BeautifulSoup

时输出错误如下
'''Here there is output of another py file I have removed'''
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python\Anaconda2\lib\site-packages\bs4\__init__.py", line 30, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "D:\Python\Anaconda2\lib\site-packages\bs4\builder\__init__.py", line 4, in <module>
    from bs4.element import ( 
  File "D:\Python\Anaconda2\lib\site-packages\bs4\element.py", line 160, in <module> 
    workbook.close()
  File "D:\Python\Anaconda2\lib\site-packages\xlsxwriter\workbook.py", line 240, in close
    self._store_workbook()
  File "D:\Python\Anaconda2\lib\site-packages\xlsxwriter\workbook.py", line 448, in _store_workbook
    allowZip64=self.allow_zip64)
  File "D:\Python\Anaconda2\lib\zipfile.py", line 756, in __init__
    self.fp = open(file, modeDict[mode])
IOError: [Errno 22] invalid mode ('wb') or filename: 'D:\\Data\\\xe6\x95\xb00\xe6\x8d\xae\xe6\xba\x90.xlsx'

1 个答案:

答案 0 :(得分:1)

您的BeautifulSoup安装已损坏:

  File "D:\Python\Anaconda2\lib\site-packages\bs4\element.py", line 160, in <module> 
    workbook.close()

那是 BeautifulSoup代码;请参阅actual bs4.element source code

您似乎已将该软件包中的常规element.py文件替换为编写Excel工作表(使用xlsxwriter软件包)的文件。您必须删除整个bs4目录并重新安装BeautifulSoup。