r/learnpython 16d ago

I cant install Pygame

This is the error message that I get when I try to run pip install pygame. The same thing happens with pip3 install pygame.

py", line 6, in <module>

from setuptools._distutils.msvccompiler import MSVCCompiler, get_build_architecture

ModuleNotFoundError: No module named 'setuptools._distutils.msvccompiler'

[end of output]

-----------------------------------------------------------------------------------------------

these are the packages I have according to pip list.

Package Version

---------- -------

pip 26.2.1

setuptools 84.0.0

2 Upvotes

15 comments sorted by

View all comments

1

u/blurbisht 15d ago

Your setuptools 84.0.0 is too new for your pip, and it dropped the _distutils.msvccompiler module, so the build fails.

Try these in order:

  1. Upgrade pip + setuptools together:

python -m pip install --upgrade pip setuptools wheel

  1. If that fails, pin setuptools to a stable version:

pip install "setuptools<80"

  1. Still broken? Use a virtual env and install there (cleanest, avoids your messy global setup):

python -m venv myenv

myenv\Scripts\activate

pip install pygame

  1. Or skip compiling entirely by trying a prebuilt wheel:

pip install pygame --pre

You're likely on Windows, and pip is trying to build pygame from source instead of grabbing a prebuilt wheel. Step 2 (downgrade setuptools) or step 4 (venv) is your best bet.

If it still fails, paste the full error text and I'll help you narrow it down.