简体   繁体   English

即使我安装了它,也无法在 Visual Studio Code 中导入 Kivy

[英]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:然后,我做了以下步骤:

  1. 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 列表中。

  2. 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

  1. I use the above installation command again.我再次使用上面的安装命令。 After the installation is completed, 'kivy' appears in the conda list and pip list.安装完成后,在 conda 列表和 pip 列表中出现“kivy”。

  2. 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.

相关问题 我在我的 python 3.6 中安装了 tensorflow,但我无法将它导入我在 visual code studio 中的项目 - I installed tensorflow in my python 3.6 but i can't import it into my project in visual code studio 即使安装了 Matplotlib 也不会导入。 使用视觉工作室代码 - Matplotlib will not import even though it is installed. Using visual studio code 我无法在 Visual Studio 代码中导入 openpyxl - I can't import openpyxl in visual studio code 我无法在 Visual Studio 代码中导入 pygame - i can't import pygame in visual studio code 无法在 Visual Studio Code 中导入库 - Can't Import Libraries in Visual Studio Code 即使我已经安装了 sklearn,我也无法导入 sklearn - I can't import sklearn even if I already installed sklearn 即使安装后也无法导入 numpy? - Can't import numpy even after I installed it? 我无法在Visual Studio Code上格式化Python文件:“没有安装用于'python'文件的文档格式化程序。” - I can't format Python file on Visual Studio Code: “There is no document formatter for 'python'-files installed.” 即使安装了 pygame 也无法导入 - Can't import pygame even though it is installed 我无法在 Visual Studio Code 上使用“from math import sqrt” - I can't use "from math import sqrt" on Visual Studio Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM