As of .py to do .exe to images and audio file used in the program is also loaded in it?

I made a game in Python using Pygame, it is now necessary to compile in the exe file so I can run it on a computer without Python. I used pyinstaller, I made an exe, but when I try to run it, he writes:
Image not found.
Then I threw all the pictures and the exe file in the same folder, but still would not open and gave an error (in the program indicated is not the directory and the name. The option of directory does not fit right, so I'm going to run a program on another computer).
Who knows how to solve the problem and can help please reply. Thanks in advance!
March 19th 20 at 09:18
1 answer
March 19th 20 at 09:20
Generally solved by reading the documentation as usual ))
And here is an example of SPECA 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 a parameter datas all files in the same directory .
Well thanks for the answer, but it is possible more in detail? Please! - lonzo.Thompson43 commented on March 19th 20 at 09:23
@lonzo.Thompson43Well.
This is something that you probably did.
pyinstaller your_game.py --noconsole --clean
Further, from the documentation.
PyInstaller analyzes myscript.py and:
Writes myscript.spec in the same folder as the script.


That means that you have created a file with the build settings directly in the same directory.

Further
For certain uses you may edit the contents of myscript.spec (described under Using Spec Files). After you do this, you name the spec file to PyInstaller instead of the script:

pyinstaller myscript.spec


You can already build an exe file using this settings file, the point is that if you have more time to write
pyinstaller your_game.py
The file is updated and all changes made will be lost so be careful.
And now actually about the changes. Most likely your already created spec file will already be announced and a and exe.
a = Analysis(
.....
)
....
exe = EXE(pyz,
a.scripts
a.binaries,
a.zipfiles,
 a.datas # make sure that this scribbling is
......
 )

In fact the datas you can add files which are needed for your script.
Further about the format change datas a list of tuples of 2 elements the first element is the name of the file where to find the second, like so. And the point means that in the same directory.
Make sure that your datas Speke declared and added to by call exe.

The file itself as you can see this python code. - Tyrese34 commented on March 19th 20 at 09:26
@Tyrese34in theory did everything seems fine but in practice it still does not start. Here is the Fial spec with my data everything seems OK, so what other puncture.
# -*- mode: python -*-

block_cipher = None

a = Analysis(['hulk_pygame.py'],
pathex=['/Users/timofej/PycharmProjects/my_first_pygame'],
binaries=[],
datas=[('Audio3.mp3','.'), ('bird.png','.'), ('blue_ruby.png','.'), ('box.jpg','.'), ('cloud1.png','.'), ('cloud2','.'), ('cloud5','.'),
('grass_platform.jpg','.'), ('green_ruby.png','.'), ('heart.png','.'), ('hulk_left1.png','.'), ('hulk_left2.png','.'), ('hulk_left3.png','.'), ('hulk_left4.png','.'),
('hulk_right1.png','.'), ('hulk_right2.png','.'), ('hulk_right3.png','.'), ('hulk_right4.png','.'), ('red_ruby.png','.')],
hiddenimports=[],
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='hulk_pygame',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True ) - lonzo.Thompson43 commented on March 19th 20 at 09:29
@lonzo.Thompson43, Hmm seems to have forgot himself, try to wrap the path in the script in this function.
def resource_path(relative_path):
 """ Get absolute path to resource, works for dev and for PyInstaller """
try:
 # PyInstaller creates a temp folder and stores path in _MEIPASS
 base_path = sys._MEIPASS
 except Exception:
 base_path = os.path.abspath(".")

 return os.path.join(base_path, relative_path)


As an example of usage for files in the directory.
refresh.setIcon(QtGui.QIcon(resource_path('refresh.png')))


After must earn. - Tyrese34 commented on March 19th 20 at 09:32

Find more questions by tags PyCharmpygamePython