5

I was trying to make a simple snake game in Python so I installed Pygame using pip install Pygame. After I installed it successfully, I tried importing Pygame but I got this error:

ModuleNotFoundError: No module named 'pygame'

I'm new to python so I'm really stuck. I imported the module by the code.

import pygame
Ruvee
  • 8,611
  • 4
  • 18
  • 44
noob
  • 51
  • 3
  • first check if it has been properly installed: do `pip freeze` and see if you can find the name of the package (be careful about pip and pip3 differences). then check if you have by mistake named any of your files as `pygame.py` because you shouldn't. if still got the problem, update your question by copying your import line here. maybe the way you call the library is wrong – Alireza May 20 '20 at 20:37
  • 1
    A similar question has already been asked - https://stackoverflow.com/questions/18317521/importerror-no-module-named-pygame - try looking there. – Hari5000 May 20 '20 at 20:39
  • I looked at the pip freeze and I found it there then checked my files and none of the was named Pygame.py – noob May 20 '20 at 20:44
  • Are you using virtualenv pyenv etc? What is your python version – Phix May 20 '20 at 21:02
  • I'm using python 3.8 – noob May 20 '20 at 21:29
  • Which IDE are you using? and what OS? – kaktus_car May 21 '20 at 11:31
  • Does this answer your question? [ImportError: No module named 'pygame'](https://stackoverflow.com/questions/18317521/importerror-no-module-named-pygame) – chluebi Jun 14 '20 at 10:55
  • if never you use conda `conda install pygame` may help – Please help me Jun 14 '20 at 10:57

4 Answers4

2

if you are on windows:

open cmd and then type:

    cd\

    cd /d C:\Windows

    cd /d C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts

and then type the command:

    pip install pygame

if you are on Mac: just try python -m pip install pygame

if you are on linux:

    pip install pygame 
Józef Podlecki
  • 10,453
  • 5
  • 24
  • 50
Omer Ozhan
  • 63
  • 1
  • 5
2

Make sure you install pygame to the 'venv' folder of your project if you're using pycharm or sublime. If you are using IDLE then open command prompt by holding: windows+R then searching cmd, or if you are on mac: cmd+space and search terminal. then type pip install pygame for windows, and python -m install pygame for mac.

Charlie C
  • 180
  • 8
0

If you are using Pycharm and your stuck goto settings and then proceed to python interpreter you will see a page listing installed modules in your Pycharm project click the small plus sign and search for pygame after that click Install Package. If you still see an error message then repeat the steps, if that doesn't work try with internet connection. I'm not good with Command Prompt but there's a way with it. NOTE: I'm still a newbie in this area so I don't know if you'll consider my ideas useful Thank you

PrinceK
  • 1
  • 2
0

I suggest using the python editor 'mu' it has pygame built in, no importing or anything, just use pygame commands like normal python commands

fozzy
  • 13
  • 6