I’m having trouble getting Kivy to work with PyCharm on Windows 7. I’ve managed to add most of the external libraries through File > Settings > Python interpreters > Paths Tab.
I’m using the Kivy version of Python.
When I run a Kivy app that works fine with using the [right click > send to > kivy.bat] method in PyCharm, it gives me this error:
Failed modules Python 2.7.3 (C:/Python27/python.exe) _imagingtk dde gtk._gtk pangocairo Generation of skeletons for the modules above will be tried again when the modules are updated or a new version of generator is available
I think that the problem might be something to do with cython, as my file fails to recognise the kivy.properties file, which is of the Cython *.pxd format.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Install and open PyCharm
- If you already had it installed and have a project open, click
File -> Settings (Ctrl + Alt + S). (If not, create a new project, and click the ‘...‘ (or
) next to interpreter, and skip step 2) - Under Project Settings, click
Project Interpreter -> Python Interpreters - Click the little green + and select local (You can also set up an interpreter to your installed python from this list)
- Point it to
..KivyPythonpython.exeand click ok (my path wasc:Program files (x86)KivyPythonpython.exesince that is where I unzipped the kivy zip file to)
I have also attached a settings.jar file. This is the kv language definition. It is not complete, but it helps a lot.
Click File->Import and select the settings.jar file.
Only FileTypes will be ticked. Import this and you will have “kv language file” definition under File->Settings-IDE Settings->File Types
Open a kv file to see the differentiation in colours, as well as autocomplete
- Widgets are type 1
- Properties are type 2
- all events (on_something) are type 3
- type 4 is just self and root.
That is all for PyCharm, the rest is Windows 7 specific
- open a command prompt and browse to your
..KivyPythonlibfolder - type
mklink /D kivy "..Kivykivykivy"(my line wasmklink /D kivy "c:Program files (x86)Kivykivykivy")
This will set up a symlink so that your all your kivy python files are read and their definitions are included, in order to get autocomplete
Now we need to set up the environment variables. You could do this per project inside PyCharm, but might as well do it in windows, so you only need to select the python interpreter each time.
Click start and type envir Select the second one. (System variables) (You could also get here with Win+PauseBreak-> Click Advanced system settings)
Click Environment variables
Now add these (once again, just point to wherever you have your kivy folder. You can also find all these in the kivy.bat file, just find and replace the variables with your path)
GST_PLUGIN_PATH c:Program Files (x86)Kivygstreamerlibgstreamer-0.10 GST_REGISTRY c:Program Files (x86)Kivygstreamerregistry.bin PATH c:Program Files (x86)Kivy;c:Program Files (x86)KivyPython;c:Program Files (x86)Kivygstreamerbin;c:Program Files (x86)KivyMinGWbin;c:Program Files (x86)Kivykivy;%PATH
Restart your machine. (For the environment variables to load)
Now when you open your kivy project, just select the Kivy interpreter you set up earlier, and bobs your uncle.
Method 2
This Kivy’s Wiki page Setting Up Kivy with various popular IDE’s has a better answer and detail commands. It is copied below with added information for Pycharm 3.4.
Go to your unzipped Kivy folder, create a symbol link for “kivy.bat” pointing to “python.bat” in the same directory (mklink python.bat kivy.bat).
Add 2 new Python interpreters in PyCharm.
- Bootstrapper: Choose the earlier created “python.bat” from the Kivy package folder.
- Project Interpreter: Choose the “python.exe” from the Python subdirectory in the Kivy package folder.
For the project interpreter, add a path to the “kivy” directory directly contained in the Kivy package folder. In PyCharm 3.4, the path tab is hidden in a sub menu. In Project Interpreter, click the tool icon next to the interpreter dropdown list, click more… (the last one), in the list of all project interpreters, select Run-Configuration Interpreter, on the right side there are five icons (+, -, edit, virtual env, and path), click path to add the Kivy sub-directory in unzipped Kivy folder.
Save all settings and ignore warnings about “Invalid output format”. Make sure that the project interpreter is set to our earlier created configuration.
Create a new run configuration and set the Python interpreter to our earlier created bootstrapper.
Simply run the configuration to execute your Kivy application
Method 3
Alternatively simply:
- Unpack the Kivy package into a folder.
- Create a symbolic link for “kivy.bat” pointing to “python.bat”.
- Add 2 new Python interpreters in PyCharm. One will be used as the
project interpreter, the other as the run-configuration interpreter.- Project Interpreter: Choose the “python.exe” from the Python subdirectory in the Kivy package folder.
- Run-Configuration Interpreter: Choose the earlier created “python.bat” from the Kivy package folder.
- For the run-configuration interpreter click on the paths-tab and add the path to the kivy directory directly contained in the Kivy package folder.
- Save all settings and ignore warnings about “Invalid output format”.
- Make sure that the project interpreter is set to our earlier created configuration.
- Create a new run/debug configuration and set the Python interpreter to our earlier created run-configuration interpreter.
- Simply run the configuration to execute your script
By having two seperate configurations it’s possible to use the “kivy.bat” or “python.bat” file to bootstrap Kivy and run the target-script and use the other configuration with the added path for proper code-completion. If PyCharm tries to use the “kivy.bat” or “python.bat” interpreter to build the module skeletons it fails/hangs. Some screenshots of the configuration:




Method 4
KV Lang Auto-completion and Highlighting
You just need to import the .jar file. Works fine on linux.
Method 5
A very simple version which worked for me was:
- Follow the instructions in Setting-Up-Kivy-with-various-popular-IDE’s
-
Install the packages in the Project Interpreter
Go to: [File]-[Settings]-[Project: ProjectName]-[Project Interpreter] Install: Pillow, image, kivy.deps.glew, kipy.deps.gstreamer, kivy.deps.sdl2, pygame, kivy
At least for me this solved my issue with the PIL module import error (The module PIL is called now Pillow) and also with the sdl2 ddl import error.
Update
Actually, I just installed the modules from the second step in PyCharm on a different PC without completing the first step and Kivy was working anyway.
Method 6
KV Lang Auto-completion and Highlighting -> Link
Description
KV Lang Auto-completion and Highlighting
Xuton has kindly developed a file type extension that gives you full syntax highlighting and auto-completion for KV files.
To install:
- Download this file .
- On Pycharm’s main menu, click File -> Import (or Import Settings).
- Select the jar file you just downloaded and PyCharm will present a dialog with filetypes ticked. Click OK.
- Restart PyCharm for the changes to take effect.
Method 7
- if you do not installed kivy go to Kivy İnstallion,
- Go to your python directory (e.g: C:Python),
- Open Lib folder (e.g: C:PythonLib),
- find site-packages and open it,
-
Copy kivy folder to PythonLib.
That’s it. Enjoy Kivy 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0