获取错误:没有名为' calendar_ui'的模块。即使在Windows 10中使用pip安装了KivyCalendar

时间:2018-01-30 09:46:56

标签: python calendar kivy

在Windows 10中使用pip安装了KivyCalendar。但是返回错误: -

  

没有名为' calendar_ui

的模块

我的代码是:

from kivy.app import App
from KivyCalendar import CalendarWidget


class MyApp(App):

    def build(self):
        return CalendarWidget()

MyApp().run()

非常感谢任何帮助。感谢

2 个答案:

答案 0 :(得分:1)

在我的项目中使用KivyCalendar时遇到了一些麻烦,因此我做了一些改进,使其可以在Python 3上运行。请确保拥有原始文件的副本。

添加在行首带有+标记的行,并删除在行首带有-标记的文件。

首先找到kivycalendar的安装目录。

KivyCalendar / 初始化 .py

 #!/usr/bin/python
 # -*- coding: utf-8 -*-

 -from calendar_ui import DatePicker, CalendarWidget
 +from .calendar_ui import DatePicker, CalendarWidget

KivyCalendar / calendar_data.py

-from calendar import TimeEncoding, month_name, day_abbr, Calendar, monthrange
+from calendar import month_name, day_abbr, Calendar, monthrange
 from datetime import datetime
 from locale import getdefaultlocale
+import locale as _locale
+
+
+class TimeEncoding:
+    def __init__(self, locale):
+        self.locale = locale
+
+    def __enter__(self):
+        self.oldlocale = _locale.setlocale(_locale.LC_TIME, self.locale)
+        return _locale.getlocale(_locale.LC_TIME)[1]
+
+    def __exit__(self, *args):
+        _locale.setlocale(_locale.LC_TIME, self.oldlocale)
+

 def get_month_names():
     """ Return list with months names """

KivyCalendar / calendar_ui.py

 from kivy.core.window import Window
 from kivy.properties import NumericProperty, ReferenceListProperty

-import calendar_data as cal_data
+from . import calendar_data as cal_data
 ###########################################################
 Builder.load_string("""
 <ArrowButton>:

答案 1 :(得分:0)

此错误仅在Python 3上发生,在Python 2.7上一切正常。

正如您在模块description中看到的那样,它仅与Python 2.7兼容:

  

编程语言:: Python :: 2.7

你在这里没有多少选择:使用Python 2.7或fork项目并创建适用于Python 3的日历。

相关问题