• Register
1 vote
82 views

Problem:

I am new in python programming. I trired to istall pygame and I wrote some code about it:

import sys
import settings
import pygame


def run_game():
  pygame.init()
  all_settings = settings()
  screen = pygame.display.set_mode(
      (all_settings.screen_width, all_settings.screen_length))
  pygame.display.set_caption("Alien Invaders")


  while True:

    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        sys.exit()

    screen.fill(all_settings.bg_color)

    pygame.display.flip()    

run_game() 

But it shows me a huge error message like below:

   ERROR: Command errored out with exit status 1:                            
     command: /home/runner/.local/share/virtualenvs/python3/bin/python -c 'i  
mport sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-gbk6qx6                
o/pygame/setup.py'"'"'; __file__='"'"'/tmp/pip-install-gbk6qx6o/pygame/setup  
.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().r  
eplace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__,   
'"'"'exec'"'"'))' egg_info --egg-base pip-egg-info                            
         cwd: /tmp/pip-install-gbk6qx6o/pygame/                               
    Complete output (12 lines):                                               
                                                                              
                                                                              
    WARNING, No "Setup" File Exists, Running "buildconfig/config.py"          
    Using UNIX configuration...                                               
                                                                              
    /bin/sh: 1: sdl-config: not found                                         
    /bin/sh: 1: sdl-config: not found                                         
    /bin/sh: 1: sdl-config: not found                                         
                                                                              
    Hunting dependencies...                                                   
    WARNING: "sdl-config" failed!                                             
    Unable to run "sdl-config". Please make sure a development version of SD  
L is installed.  
ImportError: No module named 'pygame'

Can anybody help?

10 7 2
6,060 points

Please log in or register to answer this question.

2 Answers

1 vote

Answer:

Please follow the steps that I have mentioned below:
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 (it should download and install pygame module)

Now run your code and it should work. Happy coding.

11 6 4
34,950 points
0 votes

Solution:

Three methods to check this:

1. Employing apt-cache to search and apt-get to install :

apt-cache search pygame

Result:

python-pygame - SDL bindings for games development in Python

Thereafter install:

sudo apt-get install python-pygame

2. Employ pip:

pip install Pygame

3. Manual installation:

  • Download the source from Pypi;

  • Extract the .tar.gz file, and install employ:

    python setup.py install

obs: check the python version you need to install, in case you use Python3, employ:

pip3 install Pygame

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

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

To examine it, open python IDE and type

import pygame

print (pygame.ver)

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

Only pick the similar version according to your python version and it must perform like magic. The installation feature will fetch you to a bright-blue screen as the installation (at this point you know that the installation is appropriate for you).

Thereafter go into the Python IDLE and type "import pygame" and you must not obtain any more errors.

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

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

  • Install Python, and keep in mind 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

  • In case you obtain an error in the last step, attempt:

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

And that must do it. Tested as performing on Windows 10 64bit.

10 6 4
31,120 points

Related questions

0 votes
1 answer 10 views
10 views
Question: 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 " ... '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
asked Apr 14 munim01 21k points
0 votes
1 answer 2 views
2 views
Problem: When I try to import pygame there is an error: No module named 'pygame’,how can solve this?
asked Apr 14 Humaira ahmed 50.7k points
0 votes
1 answer 5 views
5 views
Problem: Looking at the Python install, it gives the error: modulenotfounderror: no module named '_sqlite3.' Now, do I need to reinstall Python, or is there another way to get this module up and running?
asked Apr 18 anika11 32k points
1 vote
1 answer 11 views
11 views
Problem : During my learning I faced this , please help me how to fix it.
asked Mar 24 PkGuy 23.5k points
0 votes
1 answer 25 views
25 views
Problem: how to I Solve this: modulenotfounderror: no module named '_sqlite3' HELP! I need help understanding this: modulenotfounderror: no module named '_sqlite3' Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 10 Mashhoodch 13k points
0 votes
1 answer 19 views
19 views
Problem: How to I Solve this: error loading mysqldb module no module named mysqldb HELP! I need help understanding this: error loading mysqldb module no module named mysqldb Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 5 Mashhoodch 13k points
0 votes
1 answer 18 views
18 views
Problem: How to I Solve this: modulenotfounderror: no module named 'seaborn' HELP! I need help understanding this: modulenotfounderror: no module named 'seaborn' Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 5 Mashhoodch 13k points
0 votes
1 answer 11 views
11 views
Problem: Why I got the error : modulenotfounderror: no module named 'pip._internal' How to fix this erro: modulenotfounderror: no module named 'pip._internal' HELP! I need help understanding this error: modulenotfounderror: no module named 'pip._internal' Any ideas on what I need to do to fix this? Thanks!
asked Feb 28 Mashhoodch 13k points
0 votes
1 answer 84 views
84 views
Problem: Tried running a file with the following imports: from flask_sqlalchemy import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker Received the following error: ImportError: No module named 'flask_sqlalchemy' SQLAlchemy is installed. Still, I tried to reinstall into the directory in which it will be used.
asked Feb 23 Mashhoodch 13k points
0 votes
1 answer 107 views
107 views
Problem: have troubles to import the basemap module of mpl_toolkits in python. Here is what I get when I run the test.py script from the module directory: /usr/lib/python2.7/dist-packages/mpl_toolkits/basemap$ python test.py Traceback (most recent call last): File "test. ... " directory. There is no problem to import mpl_toolkits. Here is a thing I tried, to manually add the path, and the result:
asked Feb 14 Mashhoodch 13k points