How to install python application with tkcalendar module by pyinstaller?

偶尔善良 提交于 2019-12-11 15:13:09

问题


I'm trying to install python application on Windows with pyinstaller where I'm using tkcalendar. Application is working but the tkcalendar.Calendar isn't.

When I'm running application without installation everything works but if I do this, Calendar widget does not appear. I think that pyinstaller sees this module but he has problems with modules that tkcalendar is using. I tried to run pyinstaller with --path=/.../python/Lib/site-packages but this didnt worked. Also copying module files to application directory didn't help.


回答1:


The issue does not come from tkcalendar but from the fact that PyInstaller does not detect second level imports. A way to solve this issue is explained in tkcalendar's documentation in the HowTos section:

When bundling an application with PyInstaller, there is an issue with the detection of the babel dependency of tkcalendar. This can be fixed by using the --hidden-import option:

$ pyinstaller --hidden-import babel.numbers myscript.py

or by editing the .spec file:

hiddenimports=["babel.numbers"]



回答2:


If anyone found the same problem. In tkcalendar 1.5.0 there is problem with import in calendar.py.

Locate the tkcalendar folder (probably /.../python/Lib/site-packages/tkcalendar) and under calendar.py add an additional import for the missing module:

import calendar
from babel.dates import format_date, parse_date, get_day_names, get_month_names
from babel.numbers import *  # Additional Import```


来源:https://stackoverflow.com/questions/57811928/how-to-install-python-application-with-tkcalendar-module-by-pyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!