0

I installed a new version of IDLE, and I'm trying to install Pygame. I tried to use the pygame module, but when I did, the error message

Traceback (most recent call last): File "C:\Users\Kids\Desktop\Pygame Space Invaders\assets\Pygame_Space_Invaders.py", line 2, in import pygame ModuleNotFoundError: No module named 'pygame'

showed up. I'm fairly sure this is because pygame isn't installed with my current version of IDLE. I've tried numerous different pip commands trying to install it, but none of them seem to work.

'python3 -m pip install -U pygame --user', I've even tryed upgrading it with 'sudo pip3 install --upgrade pip', and 'sudo pip3 install pygame==2.0.0.dev6', and 'pip3.9 install pygame'.

Just for clarification, I already have it on my older version of IDLE, but I'm trying to get it on the newer version (3.9).

  • try running "pip3.9 install pygame" – Mannan Bhardwaj Oct 20 '20 at 21:53
  • The error message "'pip3.9' is not recognized as an internal or external command, operable program or batch file." appears when I try that. – Dwayne Hogg Oct 20 '20 at 22:25
  • 2
    How about `python3.9 -m pip install pygame`? Does that work? – Rolv Apneseth Oct 20 '20 at 22:45
  • 1
    Do you have multiple python versions installed? – Rolv Apneseth Oct 20 '20 at 22:46
  • when I run' python3.9 -m pip install pygame', it says "'python3.9' is not recognized as an internal or external command,operable program or batch file.". and yes, I do have multiple versions of python installed. Does that interfere with something? – Dwayne Hogg Oct 22 '20 at 20:08
  • That seems like python is not in your path. Try navigating to where python is installed and put it in your path. – Mannan Bhardwaj Oct 23 '20 at 18:12
  • ok. I'm not exactly sure where my 'path' is, however. is it just the python 3.9 FILE on my computer? – Dwayne Hogg Oct 23 '20 at 20:46
  • Check this out: http://www.linfo.org/path_env_var.html#:~:text=PATH%20is%20an%20environmental%20variable,commands%20issued%20by%20a%20user. – Mannan Bhardwaj Oct 24 '20 at 00:22
  • At a basic level, When running things on command prompt/terminal, the computer takes commands and looks at the "path" environment variable which consists of different directories, and looks for a match. If it finds the command in any of the directories in path, it runs it. So, if you don't have python3.9 in your path, you cant run commands with it in terminal. – Mannan Bhardwaj Oct 24 '20 at 00:24
  • I set my path to the python 3.9 folder, but I still get the same error. Is there a problem with windows 10, or do I have to set the path to the python3.9 itself? – Dwayne Hogg Oct 24 '20 at 00:54
  • Did you restart windows after you did that? – Mannan Bhardwaj Oct 24 '20 at 03:06

3 Answers3

0

Try installing a development version of pygame. The latest version is 2.0.0.dev16, get it with pip install pygame==2.0.0.dev16.

Seth
  • 2,214
  • 1
  • 7
  • 21
  • it says 'install is not recognized as a internal or external command'. Is there anything else I need to type in the command? – Dwayne Hogg Oct 22 '20 at 21:03
  • @DwayneHogg sorry SO makes it look like `install pygame==2.0.0.dev16` but it's actually `pip install pygame==2.0.0.dev16` lol – Seth Oct 22 '20 at 21:52
  • Gotcha. but then it just says the same thing for 'pip'. is there something to indicate that you're using a pip command? – Dwayne Hogg Oct 23 '20 at 20:42
  • You may have to use `python -m pip install pygame==2.0.0.dev16`. – Seth Oct 24 '20 at 00:50
0

If you don't know what version of python you're running with IDLE or are otherwise unable to access the correct python executable from your command line you can install packages using the pip._internals. Note that this is strongly discouraged by pip.

You could try the following in IDLE:

import pip
pip._internal.main(['install', 'pygame'])

If you do this, you should immediately restart IDLE afterwards and then try to import pygame.

import random
  • 3,054
  • 1
  • 17
  • 22
0

Run following commands

pip install --upgrade pip

pip install pygame==2.0.0.dev6
Gaurav Kulkarni
  • 190
  • 1
  • 14