使用'import bs4'或'from bs4 import BeautifulSoup'时出现错误
在使用 import bs4
或者 from 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 个回答
1
你的BeautifulSoup安装出了问题:
File "D:\Python\Anaconda2\lib\site-packages\bs4\element.py", line 160, in <module>
workbook.close()
这不是BeautifulSoup的代码;你可以查看真正的bs4.element
源代码。
看起来你把这个包里的正常element.py
文件替换成了一个用来写Excel表格的文件(使用了xlsxwriter
这个包)。你需要删除整个bs4
目录,然后重新安装BeautifulSoup。