How to fix ImportError: No module named pygame

2019-08-14 14:41发布

问题:

I was trying to import pygames from python using Canopy firstly and after no success I tried from terminal and in both cases I get:

import pygame Traceback (most recent call last): File "", line 1, in ImportError: No module named pygame

I did:

sudo apt-get install python-pygame

and in a desperate act also did the following:

  1. sudo apt-get install mercurial python3-pip libfreetype6-dev
  2. sudo apt-get build-dep python-pygame
  3. sudo pip3 install hg+http://bitbucket.org/pygame/pygame

and when I check on /usr/lib/python2.7 I am able to see a folder named pygame (/usr/lib/python2.7/dist-packages/pygame)

Can someone guide me on how to fix this problem?, thank you in advance

回答1:

Try searching pygame in synaptic package manager. Install it from there.



回答2:

I remember pygame giving me a few hours of pain when I installed it on OSX a few months back.

You should be stating which operating system you are on, seeing as this is an installation problem. It looks like you are on a bash shell, so I'm guessing Linux.

which python and which python3 will give the respective paths. Your OS typically needs both 2 and 3.

There will be a corresponding pip and pip3

You've crossed your wires by using pip3.

Maybe you can install pygame using pip... the Python Package Installer?

Googling 'pip pygame' gives https://askubuntu.com/questions/312767/installing-pygame-with-pip