This is a classic Snake game implemented in Python using Pygame.
- Arrow keys / WASD to move
- Eat food to grow and increase score
- Collision with walls or self ends the game
- Clean grid-based movement with consistent speed
- Pause (P), Restart (R), Quit (ESC)
- Optional sound toggle (M) if mixer is available
-
Install dependencies (already installed if you used the setup script):
pip install pygame numpy
-
Run the game:
python snake.py
If you are using the provided virtual environment, use:
.venv/bin/python snake.py
- Arrow keys or WASD: Move
- P: Pause
- R: Restart
- M: Toggle sound
- ESC: Quit
Get the packaged ZIP of the latest release:
Here are quick fixes for common issues when running the game.
Run it from Terminal instead of double‑clicking:
cd /Users/holt/snake-test
./.venv/bin/python snake.pyIf you don’t have the venv yet, create it and install deps:
cd /Users/holt/snake-test
python3 -m venv .venv
./.venv/bin/pip install --upgrade pip
./.venv/bin/pip install pygame numpy
./.venv/bin/python snake.pyYou’re likely using a different Python than your venv.
./.venv/bin/pip install pygame
./.venv/bin/python -c "import pygame, sys; print(pygame.__version__, sys.executable)"If install fails on macOS Apple Silicon, try upgrading build tools and reinstalling:
./.venv/bin/pip install --upgrade pip setuptools wheel
./.venv/bin/pip install pygame- Press M to toggle sound on/off.
- Check macOS output volume and device.
- Custom SFX/music should be placed in the project root (same folder as
snake.py). - Prefer
.wav/.oggfor sound effects;.mp3is fine for background music but can be less reliable for short SFX on some setups. - If the mixer won’t initialize on macOS, try forcing the CoreAudio driver and run again:
export SDL_AUDIODRIVER=coreaudio
./.venv/bin/python snake.py- Make sure you’re not running over SSH/headless.
- Close other full‑screen apps that might grab exclusive display.
- Update pygame:
./.venv/bin/pip install --upgrade pygame- On the start screen, press Enter or Space to begin.
- P toggles pause. If paused, HUD says “Paused”.
- Arrow keys or WASD move the snake.
Delete the best score file and it will be recreated next run:
rm -f .snake_bestReduce the grid size constant at the top of snake.py (e.g., GRID_SIZE = 20) and run again.
Run the game from Terminal and copy the full error/traceback; include your macOS version and Python version:
sw_vers
./.venv/bin/python --version
./.venv/bin/python snake.py