Warm tip: This article is reproduced from stackoverflow.com, please click
kivy python python-3.x visual-studio-code

Can't import Kivy in Visual Studio Code even I installed it

发布于 2020-12-04 07:04:47

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. Normally all other libraries are working except for 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:

Questioner
Nurqm
Viewed
32
Jill Cheng 2020-07-28 13:21

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. Of course, it wasn't in the pip list.

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

  2. Under 'from kivy.app import App', the wavy line still exists. After I reload the VSCode window, all problems disappear.

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

My environment: python:3.7.7; VSCode:1.47.2 (with conda environment); Win10.