4

I have python 3.7 with 32bit and after I did pip install pygame, I'm still getting

ModuleNotFoundError: No module named 'pygame'

when running my code. I'm using pycharm.

12
  • are you executing pip install pygame from the command line? Commented Aug 10, 2018 at 12:52
  • yes, i already have it installed, but pycharm can't import the module or something
    – altai
    Commented Aug 10, 2018 at 12:54
  • @altai click on the External Libraries link in the Project window in Pycharm. Can you see Pygame? It may be under site packages?
    – Amos
    Commented Aug 10, 2018 at 12:58
  • yes I can see it
    – altai
    Commented Aug 10, 2018 at 13:00
  • How are you starting the project? Commented Aug 10, 2018 at 13:02

4 Answers 4

2

I would just like to add to what the first answer is saying: If you are using pycharm, it still won't work until you go to file >> settings >> >> [your project name] >> python interpreter. You will see a list of packages there. If pygame is on it, then good, else, you must double click on the field where the packages are. It leads you to a little pop up box where you can type in things. If you type in pygame, you should be able to install the package.

2

To be sure that you installed the python3 proper module u need to use

pip3 install pygame
1

I ran into the same error a few days ago! Thankfully, I found the answer.

You see, the problem is that pygame comes in a .whl (wheel) file/package. So, as a result, you have to pip install it.

Pip installing is a very tricky process, so please be careful. The steps are:-

Step1. Go to C:/Python (whatever version you are using)/Scripts. Scroll down. If you see a file named pip.exe, then that means that you are in the right folder. Copy the path.

Step2. In your computer, search for Environment Variables. You should see an option labeled 'Edit the System Environment Variables'. Click on it.

Step3. There, you should see a dialogue box appear. Click 'Environment Variables'. Click on 'Path'. Then, click 'New'. Paste the path that you copied earlier.

Step4. Click 'Ok'.

Step5. Shift + Right Click wherever your pygame is installed. Select 'Open Command Window Here' from the dropdown menu. Type in 'pip install py' then click tab and the full file name should fill in. Then, press Enter, and you're ready to go! Now you shouldn't get the error again!!!

1

Probably you have several instances of Pythion on your computer. You may install pygame in one instance, but IDE uses another.

1
  • While lacking in detail, this answer described the cause of the issue I was encountering. I upgraded Python to 3.10 missing the fact that Python doesn't look to older version for installed modules.
    – codingCat
    Commented May 31, 2022 at 15:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.