7
votes

This is my situation:

enter image description here

I tried importing pygame in both python 3.4.2 and python 3.6.3 using both pip and pip3 respectively.

In the python 3.4.2 shell:

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

In the python 3.6.3 shell:

Traceback (most recent call last):
File "", line 1, in
import pygame
File "C:\Users\aditya dand\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame__init__.py", line 141, in from pygame.base import *
ModuleNotFoundError: No module named 'pygame.base'

Those are the errors that occurred.

I also used pygame-1.9.2a0-hg_5974ff8dae3c%2B.win32-py3.4.msi.
It's showing the header's file of pygame, but it's not importing something.

What can I do to solve this?

6
well the module needs to be installed by the pip associated with the interpreter that IDLE is running... you can print out the contents of sys.path to see what paths your interpreter is searching in...Grady Player

6 Answers

3
votes

Step1:

check http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame to find a Windows installer that matches the version of Python you're running. The current version of pygame is : pygame-1.9.4-cp37-cp37m-win_amd64.whl

Move this file to the folder C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts

=========================================

Step2:

open cmdand 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

Now you have successfully installed pygame package.

=========================================

Step3:

open PyCharm File >> setting make sure the "Project Interpreter" has the "pygame" package like the following:

File>>Setting>> make sure the "pygame" package is there.

1
votes

check if you have added python to path

0
votes

ans done if any one need help delete all python version from system and install python 3.5.2 from https://www.python.org/downloads/release/python-352/

then go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

and search pygame and download pygame‑1.9.3‑cp35‑cp35m‑win_amd64.whl

then go to C:\Users\"your username"\AppData\Local\Programs\Python\Python35\Scripts> in this location in cmd ( command prompt )

type this line and done " pip3 install pygame-1.9.3-cp35-cp35m-win_amd64.whl "

hope this help you

0
votes

Edit - pygame only works in python >= 3.6.*

If you are using Windows i had the same problem and i know how to fix it, follow the steps:

  1. Go to the pygame website, then go to the downloads page
  2. Once there scroll down to the windows section and copy the bit that it says to put into pip It should start with py
  3. Once this short piece of code is copied, open command prompt (search it on start, it is nothing to do with python)
  4. Open it and paste the line of code, it should say downloading and then installing and just wait a bit for it to finish. Then in the command prompt paste the example.aliens thing in and it should work.
  5. Now the complicated part, open file explorer, go to this pc and search pygame once it has fully loaded, look near the top if the list of things it came up with. There should be 2 thing that are called pygame.
  6. Now leave this open and hold the windows button and press r
  7. Then type %appdata% and press enter
  8. This will open the appdata roming file

    Look at the bit at the top that says Appdata > roaming and click on app data

  9. Then click local, then programs, then python, then python36 then go to scripts
  10. Now go back to the pygame search. Click and drag the 2nd thing called pygame into the scripts folder and you should be good to go.

Pls comment if this doesnt make sense or you would like further details

0
votes

Did you install pygame? You need to type pip install pygame or sudo install pygame into terminal. If you are using windows 10, press the windows logo key then type terminal. You can check it's installed with: pygame -H or pygame help

0
votes

You can either use cmd to install pygame type this pip install pygame (you have to make sure that python is installed) If this doesn't help Use thonny idle I use it because python doesn't work with my pc basically Thonny is a python idle which runs without the requirement of python to be installed and you can also install modules using thonny and type python code as well but make sure that if you import a module in thonny that module can be only used in thonny and can't be used in any other idle unless you install it in cmd but you don't need it as thonny idle is great so if you want to install modules like pygame in thonny 1) Open thonny 2) click on tools 3) click on open shell There you can type pip install pygame and install it successfully I have a potato pc which can't run python because it requires service pack 1 windows7 or above I don't have it I only have windows 7 so I use thonny and use pygame using thonny only. :D