I'm having trouble using the pygame module in my code. I installed pygame using the command py -3 -m pip install pygame --user
and it said it was successful. However, when running my code, I get this error No module named 'pygame'
in the Python idle 3.9.0.
Asked
Active
Viewed 1,477 times
2

Zeke Bek
- 75
- 4
-
Can you share the output of the following command? `py-3 -m site` This is to list the site packages directories. Ref: https://stackoverflow.com/questions/122327/how-do-i-find-the-location-of-my-python-site-packages-directory – Attila Viniczai Oct 20 '20 at 19:26
-
Actually the following should be enough to check: `py-3 -c "import site; print(site.ENABLE_USER_SITE)"`. User site packages might be disabled in your environment. Ref: https://docs.python.org/3/library/site.html#site.ENABLE_USER_SITE – Attila Viniczai Oct 20 '20 at 19:31
-
1sys.path = [... USER_BASE: 'C:\\Users\\username\\AppData\\Roaming\\Python' (doesn't exist) USER_SITE: 'C:\\Users\\username\\AppData\\Roaming\\Python\\Python39\\site-packages' (doesn't exist) ENABLE_USER_SITE: True (the character count was to long so I had to cut off the path) – Zeke Bek Oct 20 '20 at 19:33
-
I suggest trying to create `USER_SITE` directory by hand, then trying `pip install --user ...` again. – Attila Viniczai Oct 20 '20 at 19:34
-
How would I do that? – Zeke Bek Oct 20 '20 at 19:35
-
`py-3 -c "from pathlib import Path; import site; Path(site.USER_SITE).mkdir(parents=True)"` – Attila Viniczai Oct 20 '20 at 19:45
-
Is there any reason why you have to be using Python 3.9. It's very new so there may still be libraries and dependencies that don't work cleanly. Not sure if the situation has changed for pygame but [just over a week ago](https://stackoverflow.com/questions/64305748/how-to-install-pygame-in-windows-10-for-python-3-9), reverting to Python 3.8 was the answer. – David Buck Oct 20 '20 at 21:33
-
Ill try that, thanks for the advice. EDIT: it worked! appreciate the help. – Zeke Bek Oct 20 '20 at 21:42
3 Answers
2
You can try to download it using pip, by running the following command:
pip install pygame
or with pip3:
pip3 install pygame

Nicolas Tabet
- 139
- 1
- 5
-
2@ZekeBek - Neither worked *how*? Nothing at all happened? An error message was returned? You PC caught fire? Your cat ran away? Help people to help you. – Kingsley Oct 20 '20 at 22:02
1
just a simple command
python -m pip install pygame
or
python3 -m pip install pygame

infamous_bad_habits
- 23
- 6
-
I get no response from command prompt, it just brings me back to C:\Users\username>_ – Zeke Bek Oct 20 '20 at 19:51
0
pip install pygame -U
This should upgrade your pygame to the newest version.

Max_Meadowcroft
- 41
- 1
- 6
-
I get this error when I try that " 'pip' is not recognized as an internal or external command, operable program or batch file." – Zeke Bek Oct 20 '20 at 19:27