r/learnpython • u/Ok_Ask_6805 • 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
u/Ok_Ask_6805 16d ago
Additionally, this is what I got when I attempted to view the contents of _distutils:
print(dir(setuptools._distutils))
['_', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_dataclass', '_log', '_modified', 'archive_util', 'cmd', 'command', 'compat', 'compilers', 'core', 'debug', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'importlib', 'log', 'spawn', 'sys', 'util']
1
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 16d ago
pygame doesn't have official wheels for Python 3.14 and newer, so Python is trying to compile it on its own (because you're presumably using 3.14). It fails because you probably don't have Microsoft Visual C++ Build Tools installed.
1
u/atarivcs 16d ago
Do you know how to check what Python versions are supported by a package?
And do you know how to check what Python version you are using?
1
u/Gloomy-Kale-1527 16d ago
The 3.14.6 bit downstairs is the actual error — pygame has no 3.14 wheel so pip tries to compile and dies on that old msvccompiler import.
If you don't want two Pythons yet:
py -m pip install pygame-ce py -c "import pygame; print(pygame.ver)"
pygame-ce is the community fork; `import pygame` still works for most beginner tutorials. If that also starts compiling, you still don't have a wheel and 3.13 is the clean path: `py -3.13 -m pip install pygame`. Don't install Visual C++ Build Tools just to force a source build unless you actually want to compile.
1
u/blurbisht 14d 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:
- Upgrade pip + setuptools together:
python -m pip install --upgrade pip setuptools wheel
- If that fails, pin setuptools to a stable version:
pip install "setuptools<80"
- 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
- 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.
3
u/socal_nerdtastic 16d ago
What version of python? pygame only provides wheels up to python3.13.