解决的方案是利用pyinstaller的hook特性,步骤如下:
1.在项目目录新建hooks目录,目录中新建hooks-scrapy.py 文件,文件内容如下:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files
# This collects all dynamically imported scrapy modules and data files. hiddenimports = (collect_submodules('scrapy') + collect_submodules('scrapy.pipelines') + collect_submodules('scrapy.extensions') + collect_submodules('scrapy.utils') ) datas = collect_data_files('scrapy')
2. pyinstaller在打包过程中会生成 *.spec 文件,假设该文件名为scrapytest.spec,修改该文件,令 hookspath=['.\\hooks\\']。
3.基于spec文件重新打包,示例命令如下:
pyinstaller -F scrapytest.spec
经测试,以上方法可解决 No such file or directory 的问题。
参考链接:https://stackoverflow.com/questions/49085970/no-such-file-or-directory-error-using-pyinstaller-and-scrapy |