ImportError: No module named 'pygame'
Asked Answered
B

25

73

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.

Brassie answered 19/8, 2013 at 15:26 Comment(5)
How did you install pygame? easy_install? Build from source?Concubine
easy_install . I did not build from source .Brassie
Open up a python shell and type import sys; print sys.path. If pygame isn't on your PYTHONPATH, then you need to add it. It's weird easy_install didn't put it there. Is python3.3.2 the only python installation? Or do you also have python2.7.4 or something similar?Concubine
i had uninstalled previous installation and installed new one. What is the path for pygame. I dont think its in there. I just checked with print (sys.path)Brassie
Since you are using 3.3 32bit python, this installer works bitbucket.org/pygame/pygame/downloads/…Austriahungary
M
36

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...

Marrakech answered 4/5, 2017 at 9:33 Comment(3)
My problem was that I used the --user option to install it. When I uninstalled (python -m pip uninstall pygame) and reinstalled it without that option the runtime was able to find it. Win10x64.Maggiore
Thanks m8 --user was the problemBossuet
yep, this worked. I have python under C:\Users\Proka\AppData\Local\Programs\Python\Python38-32Entertainer
B
15

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.

Benyamin answered 11/4, 2016 at 16:2 Comment(4)
I have Python 3.4. I tried what you said, for the ones for both 3.4 and 3.5 but it said pygame-1.9.2a0-cp34-none-win32.whl is not a supported wheel on this platform or pygame-1.9.2a0-cp35-none-win32.whl is not a supported wheel on this platform.Eurhythmy
@SolomonUcko From what I remember it's likely a 32 vs. 64 bit problem. You can try getting the win64.whl file, or even just renaming the 32bit one to pygame-1.9.2a0-cp34-none-win64.whl (I've heard that can work in some cases). If none of that works, try getting the 32bit (x86) version of Python.Benyamin
it seems that using the .whl file doesn't work that well on win10/64 bit with a Python 32 bit install. But running python -m pop install pygame (as mentioned by stackoverflow.com/users/1342402/maazza below) worked perfect for me.Autotomize
It was downloading 2.4.0 version of pygame which is not available. Change it to the version from archives lfd.uci.edu/~gohlke/pythonlibs/#pygameMackenie
A
13

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.

Alixaliza answered 1/5, 2014 at 23:27 Comment(5)
Can I do this for the mac?Lavish
@SeaniRankeen Those files are for windows on the link. However on mac you can use homebrew. Instructions can be found here: pygame.org/wiki/macintoshAlixaliza
Actually, I just downloaded the 32-bit version of Python 2.7.7. Thanks thoughLavish
How do you run .whl files?Eurhythmy
@SolomonUcko you need to have wheel installed, and then I think you can run it with pip.Evangelical
O
10
  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 :-)
Oblique answered 28/12, 2017 at 5:42 Comment(0)
B
3

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.

Bechuanaland answered 26/12, 2016 at 6:34 Comment(0)
S
3

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
Sacerdotal answered 23/10, 2020 at 5:51 Comment(0)
C
3

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

Centillion answered 18/2, 2021 at 17:21 Comment(1)
Only this answer helped meKlaipeda
W
2

Resolved !

Here is an example

C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame
Wurtz answered 29/11, 2019 at 16:43 Comment(0)
N
2

I just encountered the same problem and found that I am having multiple interpreters of the different versions installed in my system and pygame got installed in one of them when I installed it using command but in my IDE another interpreter was selected so this messed up my system, try to see if you are also having the same situation.

Nigro answered 26/6, 2021 at 15:47 Comment(0)
D
1

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/

Duren answered 14/11, 2014 at 2:20 Comment(1)
Please clarify on how you install it.Eurhythmy
A
1

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.

Advisee answered 31/5, 2017 at 8:8 Comment(0)
B
1
  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
Buckskins answered 14/12, 2017 at 3:35 Comment(0)
D
1

Just use this command in the terminal python3 -m pip install -U pygame --user

Desiderate answered 22/9, 2022 at 14:51 Comment(0)
H
0

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 :)
Harriott answered 13/7, 2014 at 10:35 Comment(0)
L
0

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).

Lubricous answered 18/8, 2014 at 21:58 Comment(3)
How is this answer different from @Decoded's answer? Also this sidesteps the issue asked about.Samara
Because he makes no mention of switching to 32 bit. And your down vote was completely unnecessary.Lubricous
He explicitly mentions removing python x64 and using python x86 and the win32-py2.6 installer (x86 and win32 kind of imply 32 bit...). Secondly the downvote isn't mine.Samara
F
0

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.

Frantic answered 6/3, 2018 at 12:34 Comment(0)
M
0

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!!!

Makkah answered 28/8, 2018 at 21:39 Comment(0)
H
0

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

Humpage answered 16/4, 2020 at 11:6 Comment(0)
P
0

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.

Peyter answered 21/8, 2020 at 20:4 Comment(0)
O
0

make sure if you are on windows that your library directory is added to path

Oestrogen answered 14/8, 2021 at 9:21 Comment(0)
U
0

This may happen when pygame didn't installed, install the pygame first

pip
pip install pygame

if dont work update the PIP by goto python install folder and type

python -m pip install --upgrade pip

hope it work

Upside answered 26/8, 2021 at 12:24 Comment(0)
S
0

Try this solution: Type in to cmd (Windows):

C:\Users\'Your name'> pip install -U pygame

You should remove python -m, py -m, python3 -m before the pip Also remove --user behind it.

It will said:

C:\Users\viait>pip install -U pygame
Defaulting to user installation because normal site-packages is not writeable
Collecting pygame
  Downloading pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB)
     ---------------------------------------- 8.4/8.4 MB 1.7 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.1.2

Then test it in your IDE or cmd: (CMD example)

C:\Users\viait>python
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.1.2 (SDL 2.0.18, Python 3.10.3)
Hello from the pygame community. https://www.pygame.org/contribute.html

(IDE example)

import pygame

You can do this without any errors.

Stricklan answered 5/4, 2022 at 9:17 Comment(0)
S
0

You could use

pip install pygame

but if you use IDE like PyCharm, then you could just either install it from Python Packages or use right click at the package name then left click on Show Context Actions then left click on Install package pygame

(Personally, I recommended using Python Packages for the package installing because it has documentation with it)

Synchroflash answered 26/11, 2022 at 10:42 Comment(0)
K
-1

You gotta use Pycharm and install it in Terminal using pip install pygame and also after that enter Pycharm and hover on pygame in the "Import pygame" and in Pycharm it will tell you to download that and you can easily download it and enjoy your result

Kurtz answered 4/6, 2021 at 14:13 Comment(0)
B
-4

I was having the same trouble and I did

pip install pygame

and that worked for me!

Bucktooth answered 30/11, 2016 at 18:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.