简体   繁体   English

我的游戏的资产没有显示(auto-py-to-exe)

[英]Assets for my game aren't showing (auto-py-to-exe)

world!世界! I have a problem with my game.我的游戏有问题。 I already converted it to exe using PyInstaller (via auto-py-to-exe) and assets don't load.我已经使用 PyInstaller(通过 auto-py-to-exe)将它转换为 exe,并且资产不加载。 Any ideas how to solve it?任何想法如何解决它?

Command:命令:

pyinstaller --noconfirm --onedir --windowed --icon "D:\Programming\Softwares\Python\Projects\Bonk!\icon.ico" --add-data "D:/Programming/Softwares/Python/Lib/site-packages/panda3d-1.10.11.dist-info;panda3d-1.10.11.dist-info/" --add-data "D:/Programming/Softwares/Python/Lib/site-packages/panda3d;panda3d/" --add-data "D:/Programming/Softwares/Python/Lib/site-packages/direct;direct/" --add-data "D:/Programming/Softwares/Python/Lib/site-packages/ursina-4.1.1.dist-info;ursina-4.1.1.dist-info/" --add-data "D:/Programming/Softwares/Python/Lib/site-packages/ursina;ursina/" --paths "D:/Programming/Softwares/Python/Lib/site-packages/panda3d"  "D:\Programming\Softwares\Python\Projects\Bonk!\main.py"

I always use the spec file when adding a lot of data files to a pyinstaller project so that I can add them each programmatically.在将大量数据文件添加到 pyinstaller 项目时,我总是使用规范文件,以便我可以通过编程方式添加它们。

In your pyinstaller spec file at the top在顶部的 pyinstaller 规范文件中

import os
data_dirs = [
    "D:/Programming/Softwares/Python/Lib/site-packages/panda3d",
    "D:/Programming/Softwares/Python/Lib/site-packages/direct",
    "D:/Programming/Softwares/Python/Lib/site-packages/ursina-4.1.1.dist-info"
]
targets = [
    "panda3d/",
    "direct/",
    "ursina-4.1.1.dist-info/"
]

lst = []
for data_dir, target in zip(data_dirs,targets):
    for item in os.listdir(data_dir):
        item = os.path.join(data_dir, item)
        lst.append((item, target))

a = Analysis(
         ...
         datas=lst,
         ...

Assign the list of tuples to the datas argument in the Analysis object, and then run pyinstaller path-to-specfile.spec将元组列表分配给 Analysis 对象中的 datas 参数,然后运行pyinstaller path-to-specfile.spec

Here is a link to an explanation in the PyInstaller Docs这是 PyInstaller Docs 中解释的链接

https://pyinstaller.org/en/stable/spec-files.html#adding-files-to-the-bundle https://pyinstaller.org/en/stable/spec-files.html#adding-files-to-the-bundle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM