【问题标题】:PyInstaller ImportError: No module named spiderloaderPyInstaller ImportError:没有名为spiderloader的模块
【发布时间】:2018-04-03 05:16:09
【问题描述】:

尝试从我的Scrapy 项目创建exe 文件。我在Scrapy 项目的根目录下创建了main.py 文件:

from scrapy.crawler import CrawlerProcess
from engine_bot.engine_bot.spiders.main_spider import MainSpider


if __name__ == '__main__':
    process = CrawlerProcess({'BOT_NAME':'engine_bot',
    'SPIDER_MODULES':['engine_bot.engine_bot.spiders'],
    'NEWSPIDER_MODULE':'engine_bot.engine_bot.spiders',
    'ROBOTSTXT_OBEY':False,
    'DOWNLOAD_DELAY':0.20,
    'LOG_FILE':'scrapy.log',
    'LOG_LEVEL':'INFO',
    'ITEM_PIPELINES':{
    'engine_bot.engine_bot.pipelines.XmlExportPipeline': 300,
    }
    })
    process.crawl(MainSpider)
    process.start()

并创建了main.exe:pyinstaller --onefile main.py

当我运行 main.exe 时,它会引发:

Traceback (most recent call last):
  File "bot\main.py", line 14, in <module>
  File "site-packages\scrapy\crawler.py", line 243, in __init__
  File "site-packages\scrapy\crawler.py", line 134, in __init__
  File "site-packages\scrapy\crawler.py", line 320, in _get_spider_loader
  File "site-packages\scrapy\utils\misc.py", line 44, in load_object
  File "importlib\__init__.py", line 37, in import_module
ImportError: No module named spiderloader
[10280] Failed to execute script main

在没有 --onefile 的情况下进行了尝试,结果相同。你知道该怎么做吗?

【问题讨论】:

  • 您能否发布 pyinstaller 调用的日志或输出。这样我们就可以看到 pyinstaller 在构建您的 exe 时正在做什么。
  • 你试过 from scrapy.spiderloader import SpiderLoader 吗?
  • 在哪里?我的剧本里没有。这是scrapy(可能是动态的)导入。

标签: python windows python-2.7 scrapy pyinstaller


【解决方案1】:

我使用pyinstaller -F filename.py --hidden-import spiderloader 在通过这种情况后也会卡在其他模块中, 所以我添加了许多隐藏的导入。

这项工作对我来说。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 2012-07-10
    • 2014-01-21
    • 1970-01-01
    • 2016-11-07
    • 2021-09-28
    • 2014-11-11
    相关资源
    最近更新 更多