如何通过 pyinstaller 使用 tkcalendar 模块安装 python 应用程序?

我正在尝试在使用 tkcalendar 的 pyinstaller 在 Windows 上安装 python 应用程序。应用程序正在运行,但 tkcalendar.Calendar 没有。

当我在没有安装的情况下运行应用程序时,一切正常,但如果我这样做,日历小部件不会出现。我认为 pyinstaller 看到了这个模块,但是他对 tkcalendar 正在使用的模块有问题。我尝试使用 --path=/.../python/Lib/site-packages 运行 pyinstaller 但这没有用。将模块文件复制到应用程序目录也无济于事。


海绵宝宝撒
浏览 660回答 3
3回答

米琪卡哇伊

问题不是来自于tkcalendarPyInstaller 没有检测到二级导入这一事实。tkcalendar 的HowTos文档中解释了解决此问题的方法:使用 PyInstaller 捆绑应用程序时, 检测 tkcalendar 的 babel 依赖存在问题。这可以通过使用以下--hidden-import选项来解决:$ pyinstaller --hidden-import babel.numbers myscript.py或通过编辑.spec文件:hiddenimports=["babel.numbers"]

HUWWW

将以下代码添加到您的 python 脚本中,同时与 pyinstaller 捆绑import babel.numbers

慕桂英3389331

如果有人发现同样的问题。在 tkcalendar 1.5.0 中,在 calendar.py 中导入存在问题。找到tkcalendar文件夹(可能是 /.../python/Lib/site-packages/tkcalendar)并在calendar.py下为缺少的模块添加一个额外的导入:import calendarfrom babel.dates import format_date, parse_date, get_day_names, get_month_namesfrom babel.numbers import *  # Additional Import```
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python