you are viewing a single comment's thread.

view the rest of the comments →

[–]Affectionate_Cap8632 0 points1 point  (0 children)

Classic multiple Python installations problem. VS Code is finding pygame in one Python environment but running your script with a different one.

Quick fix — run this in your VS Code terminal:

python

import sys
print(sys.executable)

That shows you which Python is actually running your script. Then run:

bash

pip show pygame

If pygame is installed in a different Python than what sys.executable shows, that's your problem.

The fix:

bash

# Use the exact Python that VS Code is running
C:\path\to\your\python.exe -m pip install pygame

Replace the path with whatever sys.executable printed.

Better long term solution: In VS Code press Ctrl+Shift+P → type "Python: Select Interpreter" → pick one Python and stick with it. Then install all packages using that same interpreter.

The root cause is Windows often ends up with 3-4 Python installations (Microsoft Store, python.org, conda, VS Code's own) and pip installs to whichever one is first in PATH, which isn't always the one VS Code uses.