[python] ImportError: No module named 'pygame'

I have installed python 3.3.2 and pygame 1.9.2a0. Whenever I try to import pygame by typing:

import pygame

I get following error message :

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import pygame
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pygame
ImportError: No module named 'pygame'
>>> 

I went through some of the questions related to this error but none of the solution helped. I have 64 bit machine with Win7 OS

This question is related to python import pygame

The answer is


I had the same problem and discovered that Pygame doesn't work for Python3 at least on the Mac OS, but I also have Tython2 installed in my computer as you probably do too, so when I use Pygame, I switch the path so that it uses python2 instead of python3. I use Sublime Text as my text editor so I just go to Tools > Build Systems > New Build System and enter the following:

{
    "cmd": ["/usr/local/bin/python", "-u", "$file"],    
}

instead of

{
    "cmd": ["/usr/local/bin/python3", "-u", "$file"],   
}

in my case. And when I'm not using pygame, I simply change the path back so that I can use Python3.


First execute python3 then type the command import pygame,now you can see the output


For this you have to install pygame package from the cmd (on Windows) or from terminal (on mac). Just type pip install pygame .If it doesn't work for you, then try using this statement pip3 install pygame . If it is still showing an error then you don't have pip installed on your device and try installing pip first.


  1. Install and download pygame .whl file.
  2. Move .whl file to your python35/Scripts
  3. Go to cmd
  4. Change directory to python scripts
  5. Type:

    pip install pygame
    

Here is an example:

C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame

Since no answer stated this:

Make sure that, if you are using a virtual environment, you have activated it before trying to run the program.

If you don't really know if you are using a virtual environment or not, check with the other contributors of the project. Or maybe try to find a file with the name activate like this: find . -name activate.


Resolved !

Here is an example

C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame

try this in your command prompt: python -m pip intsall pygame


I was trying to figure this out for at least an hour. And you're right the problem is that the installation files are all for 32 bit.

Luckily I found a link to the 64 pygame download! Here it is: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

Just pick the corresponding version according to your python version and it should work like magic. The installation feature will bring you to a bright-blue screen as the installation (at this point you know that the installation is correct for you.

Then go into the Python IDLE and type "import pygame" and you should not get any more errors.

Props go to @yuvi who shared the link with StackOverflow.


You don't need 64 bit Python on Win64 system, just install the 32bit versions of both Python and Pygame and they will work just fine (and there is a ton more modules for them anyways).


  1. open the folder where your python is installed
  2. open scripts folder
  3. type cmd in the address bar. It opens a command prompt window in that location
  4. type pip install pygame and press enter
  5. it should download and install pygame module
  6. now run your code. It works fine :-)

go to python/scripts folder, open a command window to this path, type the following:

C:\python34\scripts> python -m pip install pygame

To test it, open python IDE and type

import pygame

print (pygame.ver)

It worked for me...


I was getting the same error. It is because your version of Pygame is not compatible with your version of Python or Pydev. Go to this link and get the proper version of Pygame for your current version of Python. Ctrl F to find it faster or click on the word python in blue. up at the top. While you instal Pygame it should find the Python path by itself. At least mind did any ways. I run Pygame through Eclipse with Python 3.4.

http://www.lfd.uci.edu/~gohlke/pythonlibs/


I was having the same trouble and I did

pip install pygame

and that worked for me!


I’m using the PyCharm IDE. I could get Pygame to work with IDLE but not with PyCharm. This video helped me install Pygame through PyCharm.

https://youtu.be/HJ9bTO5yYw0

(It seems that PyCharm only recognizes a package; if you use its GUI.)

However, there were a few slight differences for me; because I’m using Windows instead of a Mac.

My “preferences” menu is found in: File->Settings…

Then, in the next screen, I expanded my project menu, and clicked Project Interpreter. Then I clicked the green plus icon to the right to get to the Available Packages screen.


I ran into the 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 copies 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!!!


I am a quite newbie to python and I was having same issue. (windows x64 os) I have solved, doing below steps

  1. I removed python (x64 version) and pygame
  2. I have downloaded and installed python 2.6.6 x86: https://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
  3. I have downloaded and installed pygame (when installing, I have chosen the directory that I installed python): http://pygame.org/ftp/pygame-1.9.1.win32-py2.6.msi
  4. Works well :)

The current PyGame release, 1.9.6 doesn't support Python 3.9. I fyou don't want to wait for PyGame 2.0, you have to use Python 3.8. Alternatively, you can install a developer version by explicitly specifying the version (2.0.0.dev20 is the latest release at the time of writing):

pip install pygame==2.0.0.dev20

or try to install a pre-release version by enabling the --pre option:

pip install pygame --pre

Here are instructions for users with the newer Python 3.5 (Google brought me here, I suspect other 3.5 users might end up here as well):

I just successfully installed Pygame 1.9.2a0-cp35 on Windows and it runs with Python 3.5.1.

  • Install Python, and remember the install location
  • Go here and download pygame-1.9.2a0-cp35-none-win32.whl
  • Move the downloaded .whl file to your python35/Scripts directory
  • Open a command prompt in the Scripts directory (Shift-Right click in the directory > Open a command window here)
  • Enter the command:

    pip3 install pygame-1.9.2a0-cp35-none-win32.whl

  • If you get an error in the last step, try:

    python -m pip install pygame-1.9.2a0-cp35-none-win32.whl

And that should do it. Tested as working on Windows 10 64bit.


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to import

Import functions from another js file. Javascript The difference between "require(x)" and "import x" pytest cannot import module while python can How to import an Excel file into SQL Server? When should I use curly braces for ES6 import? How to import a JSON file in ECMAScript 6? Python: Importing urllib.quote importing external ".txt" file in python beyond top level package error in relative import Reading tab-delimited file with Pandas - works on Windows, but not on Mac

Examples related to pygame

How to display text in pygame? How to scale images to screen size in Pygame Pygame Drawing a Rectangle ImportError: No module named 'pygame' How to get keyboard input in pygame? Pygame mouse clicking detection Python display text with font & color? Solving "DLL load failed: %1 is not a valid Win32 application." for Pygame