Last modified: May 26, 2025 By Alexander Williams

How to Install PyGTK in Python

PyGTK is a Python wrapper for the GTK+ library. It helps create graphical user interfaces (GUIs). This guide will show you how to install PyGTK in Python.

Prerequisites

Before installing PyGTK, ensure you have Python installed. You can check using python --version. Also, install pip if it's not already available.


python --version
pip --version

Install PyGTK on Windows

On Windows, PyGTK can be installed using pip. Open Command Prompt and run the following command.


pip install PyGTK

If you encounter errors, ensure you have GTK+ runtime installed. Download it from the official GTK+ website.

Install PyGTK on macOS

For macOS, use Homebrew to install GTK+ first. Then install PyGTK via pip.


brew install gtk+
pip install PyGTK

Install PyGTK on Linux

On Linux, use the package manager to install GTK+ and PyGTK. For Ubuntu/Debian, run:


sudo apt-get install python-gtk2

For Fedora, use:


sudo dnf install pygtk2

Verify Installation

To verify PyGTK is installed, run a simple Python script. Create a file named test.py with the following code.


import gtk

window = gtk.Window()
window.set_title("PyGTK Test")
window.connect("destroy", gtk.main_quit)
window.show_all()
gtk.main()

Run the script using Python.


python test.py

A small window titled "PyGTK Test" should appear. This confirms PyGTK is working.

Common Issues

If you face errors like "ModuleNotFoundError: No module named 'gtk'", ensure PyGTK is installed correctly. Reinstall if needed.

For dependency issues, check if GTK+ is properly installed. On Linux, you may need additional packages. For example:


sudo apt-get install libgtk2.0-dev

Alternative GUI Libraries

If PyGTK doesn't meet your needs, consider other libraries like wxPython or PySide. These also offer robust GUI capabilities.

Conclusion

Installing PyGTK in Python is straightforward. Follow the steps for your OS and verify with a test script. For more Python tips, check our guide on installing packages globally vs locally.