Skip to content
Sign upLog in
← Back to Community

PyGame can't import

Profile icon

I'm trying to learn how to use PyGame, so I'm running code from an online tutorial. Upon running, couldn't import the PyGame module. A quick Google search says I need to use the shell. I opened up the shell and installed PyGame. It cached the module, so I ran the program. It still wouldn't import it. I returned to the shell, and it now can't find any file called 'pygame'.
Edit: After remembering to write 'pip', the problem is that the shell can't run 'sdl-config'. Any ideas? The log is below.

[email protected]:~/PyGame-Test$ pip install pygame Collecting pygame Using cached pygame-1.9.6.tar.gz (3.2 MB) ERROR: Command errored out with exit status 1: command: /home/runner/.local/share/virtualenvs/python3/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-gngla60m/pygame/'"'"'; __file__='"'"'/tmp/pip-install-gngla60m/pygame/'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);'"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-gngla60m/pygame/pip-egg-info cwd: /tmp/pip-install-gngla60m/pygame/ Complete output (12 lines): WARNING, No "Setup" File Exists, Running "buildconfig/" 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 SDL is installed. ---------------------------------------- ERROR: Command errored out with exit status 1: python egg_info Check the logs for full command output.
Answered by Nayoar [earned 5 cycles]
View Answer
Profile icon
Profile icon
Profile icon

You cannot use PyGame in a normal Python repl. Instead, you need to make a PyGame repl, which is treated by as a separate language. Clicking here will create one.
Although I've never actually used PyGame myself, let me know if you need any more help!
Also, please mark this comment as the answer to your question if I've helped you ;)