I am trying to place my images on a seperate file then my exe BECAUSE I have alot of images and I dont want the person scrolling throw thousands of images just to find the exe
I dont know if I am missing something on my .spec
this is what I did I made a folder for my images and added them and then the exe is outside my image folders but whats happening is its not detecting the images on that folder * am I messing something on my .spec file?
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['tower.py'],
pathex=['C:\\Users\\Habib\\Desktop\\AllMyGames\\TowerD'],
binaries=[],
datas=['C:\Users\Habib\Desktop\AllMyGames\TowerD\dist\image'],
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='tower',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False )
it will end up just saying
FAILED TO EXECUTE SCRIPT
Two problems I see:
datas
string contain backslashes (escape character for python strings), resulting in an invalid string for a path.datas
property is incorrectly structured. From the docs:
The list of data files is a list of tuples. Each tuple has two values, both of which must be strings:
- The first string specifies the file or files as they are in this system now.
- The second specifies the name of the folder to contain the files at run-time.
https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files
So, assuming your project root is C:\\Users\\Habib\\Desktop\\AllMyGames\\TowerD
, change
# Change this line
datas=['C:\Users\Habib\Desktop\AllMyGames\TowerD\dist\image']
# To this
datas=[('dist/image', 'image')]
And I think it will work.
As @Multihunter said that the path is not escaped so the script is failing, here is the simplest solution to it
replace
datas=['C:\Users\Habib\Desktop\AllMyGames\TowerD\dist\image']
with
datas=[r'C:\Users\Habib\Desktop\AllMyGames\TowerD\dist\image']
prepending the r
to your string will not escape any characters and your path will be as you wanted it to be.
See this for reference
我建议您检查您的图像是否为 ico 格式,如果它不使用: https ://icoconvert.com 如果这仍然不起作用,请重新执行 procces 但在您的 cmd promp 中写入“pyinstaller -icon”您的 .ico文件”和您的 project.py'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.