使用pyinstaller编译的可执行文件(flask,celery)的ImportError

时间:2018-04-19 06:04:28

标签: python flask celery pyinstaller

使用pyinstaller生成的可执行文件时遇到一些问题。我尝试制作一个独立的脚本工具,我的脚本是一个烧瓶+芹菜服务,它是localhost上的主机服务器。错误消息如下:

Traceback (most recent call last):
   File "mock_server\falsk_service.py", line 14, in <module>
   File "site-packages\kombu\utils\__init__.py", line 325, in __get__
   File "site-packages\celery\app\base.py", line 638, in conf
   File "site-packages\celery\app\base.py", line 456, in _get_config
   File "site-packages\kombu\utils\__init__.py", line 325, in __get__
   File "site-packages\celery\app\base.py", line 650, in loader
   File "site-packages\celery\loaders\__init__.py", line 25, in get_loader_cls
   File "site-packages\kombu\utils\__init__.py", line 96, in symbol_by_name
   File "site-packages\celery\utils\imports.py", line 101, in import_from_cwd
   File "importlib\__init__.py", line 37, in import_module   
ImportError: No module named app
[18228] Failed to execute script falsk_service

使用python flask_service.py运行时,我的代码运行正常,但运行可执行文件会出错。请帮助检查下面的代码:

# -*- coding: utf-8 -*-
import shutil, pickle, os, argparse, subprocess
import redis
from celery import Celery
from flask import Flask, jsonify, json, request, json, make_response
from return_messages import ReturnMessages
from background_scripts import BackgroundScripts

# initailizing
app = Flask(__name__)
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'], fixups=[])
celery.conf.update(app.config) ## Wrong in this line

我在互联网上搜索但找不到任何解决方案。仍然不确定根本原因。我尝试使用以下命令生成可执行文件,但结果相同。

pyinstaller --hidden_import __init__.py falsk_service.py

非常感谢。

0 个答案:

没有答案