0

I installed python(2.7) using anaconda on an ubuntu machine.

I installed pygame.

When I import pygame I get the error:

ImportError: No module named pygame

Interestingly, when I use /usr/bin/python,

the interpreter now gives no error for import python.

My code file has to run by command python x.py, not in te interpreter.

How could I resolve the issue?

Many Thanks.

Sie Tw
  • 133
  • 1
  • 12

2 Answers2

0

Which version are you using? You most import pygame to a Python 2.7 shell. http://pygame.org/download.shtml is for https://www.python.org/ version 2.7. Make sure you have downloaded and made the setup for Python 2.7 before you coming over and import pygame. If you have followed my steps, I hope you will see:

>>>
0

Pygame only works for python 2.7 and down. If you downloaded a later version make sure you go into setting in pygame and make sure you have selected python 2.7 to run. You can also do this by making a new project and when you name it scroll down to base interpreter and select python 2.7 since pygames will most likely have selected a higher version of python which will not work for pygames

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • This answer is wrong and misleading. [Pygame](https://www.pygame.org/news) was released up to python 3.10. See [Releases](https://github.com/pygame/pygame/releases). – Rabbid76 Jan 06 '22 at 10:53