Solved Pygame unable to install via pip because of no 'pkg-config' command

Hi,
I have run into an issue trying to install pygame via pip.
My main two issues seem to be that the command pkg-config is non existent (in /bin/sh ); and that "setup.py egg_info" could not execute.

Any help is appreciated!

My version of python: 3.9.13
my version of pip: 22.1.2

Here is the complete error message I get when running either pip install --user pygame and python3 -m pip install -U pygame --user
Code:
Collecting pygame
  Using cached pygame-2.1.2.tar.gz (10.1 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
 
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [32 lines of output]
      
      
      WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
      Using UNIX configuration...
      
      /bin/sh: pkg-config: not found
      /bin/sh: pkg-config: not found
      /bin/sh: pkg-config: not found
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-4ux7mnm0/pygame_105c4eeb0de54659b8330f75d435adf2/setup.py", line 359, in <module>
          buildconfig.config.main(AUTO_CONFIG)
        File "/tmp/pip-install-4ux7mnm0/pygame_105c4eeb0de54659b8330f75d435adf2/buildconfig/config.py", line 225, in main
          deps = CFG.main(**kwds)
        File "/tmp/pip-install-4ux7mnm0/pygame_105c4eeb0de54659b8330f75d435adf2/buildconfig/config_unix.py", line 208, in main
          DEPS.append(find_freetype())
        File "/tmp/pip-install-4ux7mnm0/pygame_105c4eeb0de54659b8330f75d435adf2/buildconfig/config_unix.py", line 172, in find_freetype
          pkg_config = DependencyProg(
        File "/tmp/pip-install-4ux7mnm0/pygame_105c4eeb0de54659b8330f75d435adf2/buildconfig/config_unix.py", line 39, in __init__
          self.ver = config[0].strip()
      IndexError: list index out of range
      Hunting dependencies...
      ---
      For help with compilation see:
          https://www.pygame.org/wiki/Compilation
      To contribute to pygame development see:
          https://www.pygame.org/contribute.html
      ---
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

I apologize in advanced for any slow replies.

Thanks!
 
You could simply install it pkg install py39-game
If you really want to build it with pip, you will need to have the dependency so looking at a snippet of the port Makefile's
Code:
BUILD_DEPENDS=	v4l_compat>0:multimedia/v4l_compat
LIB_DEPENDS=	libfreetype.so:print/freetype2 \
		libpng.so:graphics/png \
		libsmpeg.so:multimedia/smpeg
RUN_DEPENDS=	${PYNUMPY} \
		v4l_compat>0:multimedia/v4l_compat

USES=		compiler:c11 jpeg pkgconfig python:3.6+ sdl xorg
USE_SDL=	sdl2 ttf2 image2 mixer2
USE_PYTHON=	autoplist distutils
USE_XORG=	x11
You will have to install all the dependency required by it, for that you could just check a build run of py39-game and install all packages that is marked as dependency (in the logs you will have something like py39-game depends on XXX).
 
pkg-config on FreeBSD is provided by devel/pkgconf, but that's just for completeness. Indeed, if there's a port/package, use it instead of trying to install locally. The benefit is pkg keeps in control of the /usr/local tree (and can cleanly remove stuff).
 
Back
Top