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

  • 相关阅读:
    获取请求IP
    Excel导入工具类兼容xls和xlsx
    Openshift 4.3环境的离线Operatorhub安装
    RHEL学习
    OpenShift Service Mesh 培训作业
    OpenId Connect认证配置
    Route Sharding in OpenShift 4.3
    OpenShift 4.3环境中创建基于Go的Operator
    Quay和Clair的集成
    Quay 基础版安装和部署
  • 原文地址:https://www.cnblogs.com/vanwoos/p/12020613.html
Copyright © 2011-2022 走看看