Spyder 中使用 pd.read_html() 爬取数据,打包成 exe 后报错 'ImportError: html5lib not found' 的解决方法
在使用 Python 的 pandas 库中的 pd.read_html() 方法爬取数据时,您可能会遇到以下问题:在 Spyder 环境中代码能够正常运行,但打包成 exe 文件后却报出 'ImportError: html5lib not found' 错误,即使您的代码中并没有显式使用 html5lib 库。
这是因为 pd.read_html() 底层依赖了 html5lib 库,所以您需要安装 html5lib 库才能使程序正确运行。
解决方法:
-
安装 html5lib 库:
在您的命令行中使用以下命令安装 html5lib 库:
pip install html5lib -
手动将 html5lib 库添加到打包文件中:
如果您已经安装了 html5lib 库,但仍然出现这个错误,可以尝试在打包时将 html5lib 库手动添加到打包文件中。这可以通过使用 pyinstaller 等打包工具的选项来实现,具体方法请参考 pyinstaller 的官方文档。
通过以上方法,您应该能够成功解决 'ImportError: html5lib not found' 错误,并顺利运行您的 Python 程序。
原文地址: https://www.cveoy.top/t/topic/k43Q 著作权归作者所有。请勿转载和采集!