Building Binaries with Pygame

Hi all,

I’m using the Panda3D setup tool to build binaries of my game. However, its currently failing when it reaches an import statement for pygame. Here is the error message:

Traceback (most recent call last):
  File "__main__", line 16, in <module>
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1176, in exec_module
  File "pygame", line 38, in <module>
  File "os", line 1165, in add_dll_directory
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\laptopname\\gamename\\build\\win_amd64\\Lib\\pygame'

Here is my setup.py:

from setuptools import setup

import os, sysconfig

# Where your venv stores platform libs (packages with .pyd + DLLs)
site_plat = sysconfig.get_paths()['platlib']           # e.g. C:\...\venv\Lib\site-packages
pygame_src = os.path.join(site_plat, 'pygame')         # full pygame package path

# Tell build_apps to copy the whole folder into the build at Lib\pygame
include_files = [(pygame_src, 'Lib/pygame')]
 
setup(
    name='game1',
    options={
        'build_apps': {
            'gui_apps': {
                'game1': 'Menu.py',
            },
 
            'log_filename': '$USER_APPDATA/game1/output.log',
            'log_append': False,
 
            'include_patterns': [
                'fonts/**',
                'images/**',
                'models/**',
                'sounds/**',
                'contact_details',
                'questions',
                'venv\Lib\site-packages\pygame'
            ],
 
            # only needed if dynamic imports are used:
            'include_modules': [
                'game',
                'database_interactions',
                'pygame', 
                'pygame.freetype'
            ],
 
            'plugins': [
                'pandagl',
                'p3openal_audio',
            ],
            'platforms': ['win_amd64'],
            'prefer_discrete_gpu': True,
        }
    }
)

Any help would be greatly appreciated! Very stuck with this one.

Thanks,
Jack

Try replace \ with / in pygame addr.

Welcome to the community!

Your include_files = line does nothing, because it’s not being passed to setup() in any meaningful way.

You need to include the pygame DLLs somehow. Apparently it looks for them in a Lib/pygame directory. So you could try something like this:

            'package_data_dirs': {'pygame': [('pygame/*.dll', 'Lib/pygame', ())]}

I’m a bit confused though because if I look at the actual pygame wheel, it doesn’t try to use a special Lib/pygame directory, it just looks for them in the directory of the executable. Which version of pygame are you using?