简体   繁体   English

无法让 Kivy 在 Visual Studio Code 中工作

[英]Cant get Kivy to work in Visual Studio Code

As stated above i cant seem to work with kivy while using Visual Studio Code.如上所述,在使用 Visual Studio Code 时,我似乎无法使用 kivy。 I can see that there are a few other posts like this one but im not sure if they are the same problem or not so until im notified that i need to move my post i wont.我可以看到还有其他一些类似的帖子,但我不确定它们是否是同样的问题,直到我通知我需要移动我的帖子我不会。

So i am working through the book Creating Apps in Kivy Mobile with Python, I am at the very first example.因此,我正在使用 Python 在 Kivy Mobile 中创建应用程序一书,这是第一个示例。 i will post my code and the output from my terminal and hopefully someone can help.我将从我的终端发布我的代码和 output,希望有人能提供帮助。

heres the code这是代码

first file main.py第一个文件 main.py

from kivy.app import App


class WeatherApp(App):
    pass

if __name__ == '__main__':
    WeatherApp().run()

and here is the Kivy file: weather.kv这是 Kivy 文件:weather.kv

Label:
    text: "Hello World"

and lastly here is my output from the terminal最后是我的 output 从终端

$ /Users/fau57/.pyenv/versions/3.9.2/bin/python "/Users/fau57/Documents/Development/Python/Kivy/Creating Apps in Kivy/Practice Code/main.py"
Traceback (most recent call last):
  File "/Users/fau57/Documents/Development/Python/Kivy/Creating Apps in Kivy/Practice Code/main.py", line 1, in <module>
    from kivy.app import App
ModuleNotFoundError: No module named 'kivy'

Please use the following command in terminal to install the kivy package:请在终端中使用以下命令安装kivy包:

pip install kivy

在此处输入图像描述

Some things you might check...有些事情你可能会检查...

  1. Kivy doesn't work with the latest version of Python (3.10) so make sure you're using 3.9.x. Kivy 不适用于最新版本的 Python (3.10),因此请确保您使用的是 3.9.x。
  2. The book you're working from was published in 2014 and the code samples were tested with Kivy 1.8.您正在使用的书于 2014 年出版,代码示例使用 Kivy 1.8 进行了测试。 A lot has changed since then and you might consider, instead, using more recent learning material.从那以后发生了很多变化,您可能会考虑使用更新的学习材料。 When I was working my way through "Creating Apps in Kivy Mobile with Python" I only got to page 13 when I ran into a deprecated widget, so I abandoned the book.当我阅读“使用 Python 在 Kivy Mobile 中创建应用程序”时,我只到了第 13 页,却遇到了一个已弃用的小部件,所以我放弃了这本书。
  3. It's recommended that Kivy be used in a virtual environment, so it's actually simpler to set it up manually and write your code with Notepad++ instead of VS Code.建议在虚拟环境中使用 Kivy,因此手动设置它并使用 Notepad++ 而不是 VS Code 编写代码实际上更简单。 Notepad++ has a syntax highlighter for Kivy. Notepad++ 有一个用于 Kivy 的语法高亮。 Yes, you'll do more typing, but the more code you type, the better you'll learn.是的,你会做更多的输入,但是你输入的代码越多,你就会学得越好。 VS Code and its ilk have made us all lazy. VS Code 和它的同类让我们都变得懒惰了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM