zoukankan      html  css  js  c++  java
  • 使用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

  • 相关阅读:
    Python—模块
    Python之路_Day5
    Python之路_Day4
    Py获取本机指定网卡的ip地址
    Python之路_Day3
    Python之路—Day2作业
    Python之路—Day2
    Python之路—Day1作业
    Python之路—Day1
    Python数据类型
  • 原文地址:https://www.cnblogs.com/vanwoos/p/12020613.html
Copyright © 2011-2022 走看看