Python Forum
Unable to install pygame (but it seems to already be installed)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to install pygame (but it seems to already be installed)
#1
I have been unsuccessful installing pygame (but see notes below). Here is what I did:

Output:
sudo python3 -m pip install -U pygame==2.6.0 The directory '/home/garth/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/garth/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting pygame==2.6.0 Downloading https://files.pythonhosted.org/packages/72/49/bd2fcbadb6a55bb24284bad4f530189401c99ffc234d51ba54756a776eb2/pygame-2.6.0.tar.gz (15.8MB) 100% |████████████████████████████████| 15.8MB 46kB/s Complete output from command python setup.py egg_info: Skipping Cython compilation WARNING, No "Setup" File Exists, Running "buildconfig/config.py" Using UNIX configuration... /bin/sh: 1: sdl2-config: not found /bin/sh: 1: sdl2-config: not found /bin/sh: 1: sdl2-config: not found /bin/sh: 1: pkg-config: not found /bin/sh: 1: pkg-config: not found /bin/sh: 1: pkg-config: not found /bin/sh: 1: freetype-config: not found /bin/sh: 1: freetype-config: not found /bin/sh: 1: freetype-config: not found Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-n22qqeul/pygame/setup.py", line 426, in <module> buildconfig.config.main(AUTO_CONFIG) File "/tmp/pip-build-n22qqeul/pygame/buildconfig/config.py", line 234, in main deps = CFG.main(**kwds, auto_config=auto) File "/tmp/pip-build-n22qqeul/pygame/buildconfig/config_unix.py", line 245, in main raise RuntimeError('Unable to run "sdl-config". Please make sure a development version of SDL is installed.') RuntimeError: Unable to run "sdl-config". Please make sure a development version of SDL is installed. Hunting dependencies... WARNING: "sdl2-config" failed! WARNING: "pkg-config freetype2" failed! WARNING: "freetype-config" failed! --- For help with compilation see: https://www.pygame.org/wiki/CompileUbuntu To contribute to pygame development see: https://www.pygame.org/contribute.html --- ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-n22qqeul/pygame/
The 'error' is the last line. Is this a problem with pip??

The thing is, pygame IS already installed! (but there seems to be multiple instances) More notes:
  1. Mu Editor is using pygame 1.9.4 (Python3), but Geany (with Python2) is using 2.0.3, and 2.6.0 (with Python3) in Thonny.
  2. Geany is not able to use pygame with Python3 (it only works with Python2)
  3. I don't want to add to this specific issue (but it might be related): I also cannot 'install' pygame zero (but it TOO is 'installed' since i can use it with Mu Editor). Ultimately, I cannot run pgzrun, or other commands (but AGAIN, Mu can run pygame zero programs).

I tried searching for help online, but no helpful (or clear) answers. I fear that there are MULTIPLE problems here, and my system is messed up! I would really appreciate some (clear) help to guide me.
Reply
#2
Hey! No worries — you’re not alone in running into this kind of thing. Let me break it down and guide you step by step using simple words.

🧩 What’s going wrong?

You're trying to install Pygame version 2.6.0 using this command:

sudo python3 -m pip install -U pygame==2.6.0

But you're getting a lot of scary-looking errors. Don’t worry — here’s what they mean in plain English:

1. Cache warnings:
You see messages like “The directory is not owned by the current user.” This just means you’re using sudo (admin mode), but your system wants you to use sudo -H instead for safety. Not a big deal, but let’s fix it later.

2. The real problem is here:
RuntimeError: Unable to run "sdl-config". Please make sure a development version of SDL is installed.

Translation: Pygame needs some extra stuff to work, and your system doesn’t have those installed yet. Specifically, it needs SDL and a few other “dev packages.”

🛠️ How to fix it

Let’s fix things step by step.

1. Install the missing packages:

Open a terminal and type this:

sudo apt update
sudo apt install libsdl2-dev libfreetype6-dev libportmidi-dev libavformat-dev libswscale-dev libsmpeg-dev libjpeg-dev libtiff5-dev libx11-dev libxext-dev python3-dev pkg-config

This installs all the stuff Pygame needs to build and run properly.

Then install Pygame:

Try this after installing the dev packages:

sudo -H python3 -m pip install -U pygame==2.6.0

(The -H flag helps avoid that warning about user folders.)

✅ That should fix the error about "sdl-config not found."

About the “multiple versions” thing:

Yeah, it sounds like your system has multiple Python setups (Python 2 and 3), and different editors are using different ones.

  1. Mu Editor: using pygame 1.9.4 on Python 3

    Geany: using Pygame 2.0.3 on Python 2

    Thonny: using Pygame 2.6.0 on Python 3

This is super common, and can definitely cause confusion.

💡 Quick tip: To see which Python and Pygame versions your terminal is using, run:

python3 -m pygame.examples.aliens

If it works, great! If not, we can talk about setting up a virtual environment (a clean, safe place for one version of Python and Pygame).

👾 And about Pygame Zero:

It probably installed under one Python version, but you’re trying to run it from another. Let me know which editor/terminal you want to use for pgzrun, and I can help set it up correctly.

Let’s take it one step at a time — I’m here to help! Want to try installing those packages and see what happens?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cannot install and use pygame zero garthE 7 2,869 Sep-24-2024, 11:56 AM
Last Post: garthE
  Can't get pygame to install djwilson0495 13 15,355 Dec-07-2020, 01:30 PM
Last Post: djwilson0495
  Trying to install pygame Mac OS x high sierra giladal 2 3,693 Oct-18-2020, 09:27 PM
Last Post: nilamo
  Error to install pygame skp 1 4,266 Apr-14-2020, 05:17 PM
Last Post: joe_momma
  Unable to exit Pygame window Hesper 2 5,207 Mar-30-2020, 08:59 AM
Last Post: Hesper
  PIP cannot install Pygame Amaly84 6 13,605 Sep-04-2019, 07:59 PM
Last Post: Amaly84
  pip install pygame choking on SDL dependency sneakyimp 20 17,242 Jan-23-2019, 12:36 PM
Last Post: metulburr
  pip can't install pygame SheeppOSU 1 10,340 Dec-08-2018, 08:20 PM
Last Post: snippsat
  How to install Pygame chappie 2 4,251 Dec-06-2017, 10:47 PM
Last Post: chappie
  How to begin coding for game making [Install pygame on mac] mattkrebs 2 6,153 Apr-02-2017, 10:57 AM
Last Post: machrider

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020