T
T
Timofey2019-03-30 15:12:24
Python
Timofey, 2019-03-30 15:12:24

How to make an .exe from .py so that the pictures and audio file used in the program are also loaded into it?

I made a Python game with Pygame, now I need to compile it into an exe file so I can run it on a non-Python machine. I used pyinstaller, it made me an exe, but when I try to run it, it says:
Image not found.
Then I threw all the pictures and the exe file into one folder, but it still didn’t open and gave an error (the program does not indicate the directory, but the name. The option with the directory does not immediately work, since I will run the program on another computer).
Anyone who knows how to solve the problem and can help please answer. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey_Dolg, 2019-03-30
@Andrey_Dolg

In general, it is solved by reading the documentation as usual))
And so here is an example of a spec for pyinstaller

a = Analysis(['GUI.py'],
             pathex=['path to project', os.path.join(ntpath.dirname(PyQt5.__file__), 'Qt', 'bin')],
             datas=[('edit.svg','.'),('refresh.png','.'),('remove.svg','.'),('unknown.png','.'),('framework.png','.')],
             hiddenimports=['sip','hashlib'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='app_name',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
      manifest=None,
          console=False,
      uac_admin=True,
          icon='framework.ico')
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='Ver1.03')

You need the datas parameter for all files in the same directory as .

I
IDzone-x, 2020-06-10
@IDzone-x

Try to make a video of howdy ho "python in ex HOW?"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question