使用pyinstaller打包使用scrapy模块的程序运行时出现No such file or directory的问题解决


解决的方案是利用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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM