Last modified: May 26, 2025 By Alexander Williams

How to Install PyOpenGL in Python

PyOpenGL is a Python binding for OpenGL. It allows you to create 3D graphics in Python. This guide will help you install PyOpenGL easily.

Prerequisites

Before installing PyOpenGL, ensure you have Python installed. You can check this by running:


python --version

If Python is not installed, follow our guide on how to install Python on macOS with Homebrew or how to install Python on Fedora.

Install PyOpenGL Using pip

The easiest way to install PyOpenGL is using pip. Open your terminal and run:


pip install PyOpenGL

This will download and install the latest version of PyOpenGL. If you need a specific version, specify it like this:


pip install PyOpenGL==3.1.6

Install PyOpenGL with Accelerate Module

For better performance, install the accelerated module:


pip install PyOpenGL_accelerate

This module optimizes PyOpenGL for faster rendering.

Verify the Installation

To ensure PyOpenGL is installed correctly, run a simple test script. Create a file named test_opengl.py:


from OpenGL.GL import *
from OpenGL.GLUT import *

def draw():
    glClear(GL_COLOR_BUFFER_BIT)
    glBegin(GL_TRIANGLES)
    glVertex2f(0.0, 0.5)
    glVertex2f(-0.5, -0.5)
    glVertex2f(0.5, -0.5)
    glEnd()
    glutSwapBuffers()

glutInit()
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutCreateWindow(b"PyOpenGL Test")
glutDisplayFunc(draw)
glutMainLoop()

Run the script:


python test_opengl.py

If a window with a triangle appears, PyOpenGL is working correctly.

Common Issues and Fixes

Missing Dependencies: Some systems may require additional libraries. On Ubuntu, install them with:


sudo apt-get install freeglut3-dev

Permission Errors: If you encounter permission issues, use --user with pip:


pip install --user PyOpenGL

For more on managing Python packages, see our guide on installing Python packages globally vs locally.

Conclusion

Installing PyOpenGL in Python is simple with pip. Verify the installation with a test script. For better performance, install the accelerated module. Now you're ready to create 3D graphics in Python!