How to install the Kivy module in Python

This answer will show us how to install the Kivy 2.0.0 module using pip in Python 3.8+. To start, create a virtual environment before using Kivy. Some tools or modules might affect the Kivy module and cause issues in the execution of our code.

If we are using Pycharm or another text editor that automatically creates a virtual environment, these next few steps are not needed. If we decide to skip making the virtual environment steps, go to Step 6.

Below are the steps to create a virtual environment and install Kivy with pip (Click the hints for screenshots) :

Step 1) Go to the desired directory.

Step 2) Type cmd in the URL of the directory and press enter to open the command terminal.

Step 3) Type python -m pip install --upgrade pip setuptools virtualenv and press enter.

Linux users may have to use python3 instead of python in the command terminal and add a - -user flag in the commands outside of the virtual environment.

Step 4) Type python -m virtualenv kvenv.

Step 5) Type kvenv\Scripts\activate in the command terminal and press enter.

The virtual environment is now set up. For each use of the Kivy module outside this directory, we will have to follow these steps again. However, if we use a text editor, like Pycharm, that automatically creates a virtual environment, we may not have to.

Now, it’s time to use pip to install Kivy. Before we use the commands to install Kivy, we must decide which version we need. There are three types kivy[base], kivy[base, media], and kivy[full]. Each type has different dependencies and is, ultimately, your preference. Let’s install kivy[full] for this project. However, installation with the other types is practically the same.

Step 6) The final step! Open the command terminal with (kvenv), type python -m pip install kivy[full], and press enter.

Note: If we look at Kivy’s website, we will see that it says to type “python -m pip install kivy[full] kivy_examples” instead of “python -m pip install kivy[full].” However, both ways will work.

The Kivy module has been installed inside a virtual environment we created. To verify whether it’s correctly installed, use the pip show kivy command.

Now it’s time for us to implement all the steps mentioned above in a terminal to understand the process better.

Note: We are using a Linux terminal for the implementation. In the Linux terminal, the command used to activate a virtual environment is: source /path/to/venv/bin/activate, and instead of python command, the command would be python3.

Now use the following commands one by one on the terminal.

python3 -m pip install --upgrade pip setuptools virtualenv
python3 -m virtualenv kvenv
source /kvenv/bin/activate
python3 -m pip install kivy[full]
pip show kivy
Terminal 1
Terminal
Loading...

Conclusion

This concludes how to install the Kivy module. To sum it up, it is recommended that we create a virtual environment per the app or directory that we intend to use with Kivy. Once the virtual environment is created, we can install Kivy using pip. Then we will be ready to start coding our app with Kivy.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved