Unable to get Kivy to work with Pycharm Community edition

Answered

I have installed Python 3.7.4 on windows 10  and installed Kivy via PIP .   Kivy appears to be installed correctly as I can run the folloing code in a py file from the Python IDLE

import kivy
kivy.require('1.0.6') # replace with your current kivy version !

from kivy.app import App
from kivy.uix.label import Label


class MyApp(App):

def build(self):
return Label(text='Hello world')


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

However either copying this code or dropping the file in pycharm and running I get an error "import kivy
ModuleNotFoundError: No module named 'kivy'   "

I have python installed in C:\Users\username\AppData\Local\Programs\Python\Python37\python.exe

I've tried selecting Kivy as interpreter under "Add Python Interpreter"  and pointing toward the Kivy directory which is in directory

C:\Users\gmoor\AppData\Local\Programs\Python\Python37\Lib\site-packages\kivy        

However it does not allow me to select OK . 

Not sure what I'm or have done wrong here.  Help very much appreciated. Thank you

1
4 comments

Hi,

Most likely you are using two different interpreters. One of them has kivy installed and another one doesn't.

Please follow the tutorial to install kivy to your current Project Interpreter in PyCharm https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html

Or use the same interpreter you use for Python IDLE.

0
Avatar
Permanently deleted user

Hi Sergey,  thank you for your reply.   In between my posting my query and you posting your reply, I manage to have it work if I have a project that is in the kivy_venv directory but no if the project is outside the kivy_venv directory even though I am now able to select the kivy interpreter "Python 3.7 (kivy_venv)" and save it in settings.

1
Avatar
Permanently deleted user

Gmoore, can you please expand on your explanation please. Should the project be in the kivy_venv directory?

1
Avatar
Permanently deleted user

I was facing the same issue. After trying it multiple times, I came across this solution and it worked.

Basically, you need to create an interpreter which points to kivy folder('kivy_venv' folder which was created using steps similar to this installation link: https://kivy.org/doc/stable/installation/installation-windows.html#start-a-kivy-application

  1. Open Pycharm
  2. Click 'File' tab in upper left corner
  3. click on 'Settings'
  4. click on 'Project:test'
  5. click 'Python Interpreter'
  6. click on 'Settings symbol' (wheel shaped) next to 'Python Interpreter'
  7. click on 'show all'
  8. click on '+' plus symbol
  9. Set 'Location' to the folder where 'PycharmProject' folder is situated.(To find out PycharmProject folder location, click on File->Open->ProjectName ) (I would recommend you to create a new folder in PycharmProject say 'kivyProject1') In my case, Location is C:\Users\Shraddha\PycharmProjects\kivyProject1
  10. Set 'Interpreter' to the folder where kivy was installed.(If you installed kivy using steps at https://kivy.org/doc/stable/installation/installation-windows.html#start-a-kivy-application ,  you will have 'kivy_venv' folder. Copy the complete address of 'kivy_venv\Scripts\python.exe' and paste at 'Interpreter' ) In my case, Interpreter is C:\Users\Shraddha\AppData\Local\Programs\Python\Python37\kivy_venv\Scripts\python.exe
  11. Click on 'Edit' (a pencil shaped symbol at right side) and set name Name: Python 3.7 (kivyenv1) Keep Location as it was.In my case location was, Location:C:\Users\Shraddha\PycharmProjects\kivyProject1\Scripts\python.exe
  12. Click OK. Then OK.  Now you are out of 'Settings'.

  13. Create new python program filename.py to check if kivy is imported. For that, Click File->Create new project and ensure its location is C:\Users\Shraddha\PycharmProjects\kivyProject1\filename.py

  14. In filename.py, type import kivy and run by clicking on PLAY button. You must get logs as : succesfully imported kivy

 

0

Please sign in to leave a comment.