首页 文章

即使我安装了模块,也没有名为'Kivy'的模块

提问于
浏览
0

据我所知,我已经安装了Kivy和所有需要的文件,但我仍然收到此错误消息,我不知道为什么 .

from kivy.app import App
from kivy.uix.gridlayout import GridLayout


class Container(GridLayout):
    pass


class MainApp(App):

    def build(self):
        self.title = 'Awesome app!!!'
        return Container()

if __name__ == "__main__":
    app = MainApp()
    app.run()

这是我收到的错误消息:

Traceback (most recent call last):
  File "C:\Users\Yassi\OneDrive\Afbeeldingen\Bureaublad\main.py", line 1, in <module>
    from kivy.app import App
ImportError: No module named 'kivy'

我通过anaconda安装了Kivy,因此kivy的文件可能安装在错误的目录中 . 无论哪种方式,我都不知道如何解决这个问题 .

我在Windows 10操作系统上运行此程序,并使用python-3

Edit: It might have something to do with how I refer to the python interpreter. I can't find the location of the python interpreter though so now I'm stuck.

Edit2: This is the place where I installed python: C:\Program Files\IBM\SPSS\Statistics\25\Python3. Any way how I can refer to this? I think this is where the problem lies.

1 回答

  • 0

    检查当前环境中是否安装了kivy:

    import pip._internal as pip
    
    print([i.key for i in pip.get_installed_distributions()]
    # or 
    pip.main(['freeze'])
    

    因此,您将看到在这个环境中是否安装了kivy . 为了确保你在这个环境中安装了kivy,你可以这样写:

    try:
        from kivy.app import App
    except ImportError:
        import pip._internal as pip
        pip.main(['install', 'kivy'])
        from kivy.app import App
    

相关问题