[英]Can't import Kivy in Visual Studio Code even I installed it
I'm using Visual Studio Code for Python and I'm pretty sure that I installed required libraries from command prompt and also from Visual Studio Code's terminal.我正在为 Python 使用 Visual Studio Code,我很确定我从命令提示符和 Visual Studio Code 的终端安装了所需的库。 Normally all other libraries are working except for Kivy.
通常所有其他库都在工作,除了 Kivy。 I don't understand why.
我不明白为什么。 Here is the imports that not working when I tried to import:
这是我尝试导入时不起作用的导入:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
and here is the error:这是错误:
ModuleNotFoundError: No module named 'kivy'
and here is the files that I installed with pip:这是我用 pip 安装的文件:
According to the information you provided, I have reproduced the issue you mentioned.根据你提供的信息,我已经复制了你提到的问题。
Then, I did the following steps:然后,我做了以下步骤:
I tried to use pip to install 'kivy', but it didn't work.我尝试使用 pip 安装“kivy”,但没有成功。 Of course, it wasn't in the pip list.
当然,它不在 pip 列表中。
I tried to install 'kivy' with conda and then the installation was successful, but it only appears in the conda list, not in the pip list.我尝试用 conda 安装 'kivy',然后安装成功,但它只出现在 conda 列表中,而不出现在 pip 列表中。
conda install kivy -c conda-forge
I use the above installation command again.我再次使用上面的安装命令。 After the installation is completed, 'kivy' appears in the conda list and pip list.
安装完成后,在 conda 列表和 pip 列表中出现“kivy”。
Under ' from kivy.app import App
', the wavy line still exists.在'
from kivy.app import App
'下,波浪线仍然存在。 After I reload the VSCode window, all problems disappear.重新加载 VSCode window 后,所有问题都消失了。
As a test, I used the following code and ran the results successfully:作为测试,我使用了以下代码并成功运行了结果:
from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import Screen, ScreenManager from kivy.uix.button import Button class TestApp(App): def build(self): return Button(text = "hello") TestApp().run()
VSCode opens a Test file with content 'hello'. VSCode 打开一个内容为“hello”的测试文件。
My environment: python:3.7.7;我的环境:python:3.7.7; VSCode:1.47.2 (with conda environment);
VSCode:1.47.2(带conda环境); Win10.
赢10。
Check your installed packages检查您安装的软件包
pip list
If you don't find kivy try to install again or go here如果您没有找到 kivy 尝试再次安装或 go 在这里
https://kivy.org/doc/stable/installation/installation-windows.html https://kivy.org/doc/stable/installation/installation-windows.html
Both "conda" and "pip" methods are given.给出了“conda”和“pip”方法。
Uninstall kivy, even delete files from explorer to be sure.卸载 kivy,甚至可以从资源管理器中删除文件。 Then try this:
然后试试这个:
pip install kivy
Whish that your problem will be solved.希望你的问题能得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.