"pygame.error: No available video device" on Repl

Viewed 703

I keep receiving Error: pygame.error: No available video device. This works on python default IDLE that comes when installing python 3.10 on Windows but doesn't work with Replit(Online IDLE).

I installed pygame into Relpit as you can see here

I'm getting Error from this part of the code:

import pygame
import math
pygame.init()

WIDTH, HEIGHT =  800, 800
WIN = pygame.display.set_mode((WIDTH, HEIGHT))  <<<-- ERROR LINE
pygame.display.set_caption("Planet Simulation")

This is the the Output:

pygame 2.1.2 (SDL 2.0.16, Python 3.8.12)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "main.py", line 6, in <module>
    WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.error: No available video device

So my question is, Is this the IDLE fault or is the code wrong. Also How do I fix it?

1 Answers

Find the PyGame template when making a new repl

With replit you have to make sure to use the provided pygame template - which you can search for from the link provided - when creating a "special project" so simply:

  1. Make a new project
  2. Select the PyGame template
  3. copy your code into the new project

and it should fix it!

Related