使用apscheduler进行Pyinstaller 3.3.1和3.4.0-dev构建

打招呼!


我正在尝试使用PyInstaller进行构建。配置:Python 3.6.5 pip 10.0.1,操作系统:Ubuntu 18.04。使用virtualenv(也曾尝试与一起使用python -m venv)。


我的应用程序使用apscheduler,websocket,_thread和它看起来像一些相关的模块有进口的问题。试过pyinstaller --onefile mymain.spec&pyinstaller --onedir mymain.spec。在两种情况下问题仍然存在。如果程序没有冻结,程序将正常运行。


这是我尝试运行生成的可执行文件时遇到的错误:


Traceback (most recent call last):

  File "apscheduler/schedulers/base.py", line 882, in _create_plugin_instance

KeyError: 'interval'


During handling of the above exception, another exception occurred:


    Traceback (most recent call last):

      File "cmonitorcli/services/socket_client.py", line 70, in run

      File "cmonitorcli/services/scheduler.py", line 36, in add_update_job

      File "apscheduler/schedulers/base.py", line 413, in add_job

      File "apscheduler/schedulers/base.py", line 907, in _create_trigger

      File "apscheduler/schedulers/base.py", line 890, in _create_plugin_instance

    LookupError: No trigger by the name "interval" was found

    ^CTraceback (most recent call last):

      File "websocket/_app.py", line 283, in run_forever

      File "websocket/_app.py", line 50, in read

    KeyboardInterrupt


    During handling of the above exception, another exception occurred:


    Traceback (most recent call last):

      File "cmonitorcli/main.py", line 20, in <module>

      File "cmonitorcli/main.py", line 8, in main_job

      File "cmonitorcli/client.py", line 29, in __init__

      File "cmonitorcli/services/socket_client.py", line 31, in connect

      File "websocket/_app.py", line 283, in run_forever

    KeyboardInterrupt

requirements.txt:


jsonpickle==0.9.6

pkg-resources==0.0.0

six==1.11.0

websocket-client==0.48.0

apscheduler==3.5.1

pyinstaller==3.3.1

我需要进行--onefile构建。


请注意hiddenimports与这些配合使用的示例:


missing module named 'wsaccel.xormask' - imported by websocket._abnf

missing module named numpy - imported by websocket._abnf

missing module named win32evtlog - imported by logging.handlers

和其他任何模块都无济于事-它们仍然会在日志中显示带有missing module标志


摇曳的蔷薇
浏览 440回答 3
3回答

慕森卡

根据Alex Grönholm回复:问题的确是因为APScheduler使用setuptools入口点来查找触发器类。解决方案是实例化触发器并传递给add_job():from apscheduler.schedulers.background import BackgroundSchedulerfrom apscheduler.triggers import intervalscheduler = BackgroundScheduler()trigger = interval.IntervalTrigger(seconds=3)scheduler.add_job(lambda: job_func(ws), trigger=trigger, id='status_update_job', replace_existing=True)

桃花长相依

问题在于pyinstaller不打包APScheduler查找触发器类所需的setuptools入口点。解决方法是手动导入和使用触发器。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python