pyinstaller 不显示图像和图标 [英] pyinstaller does not show images and icon

查看:132
本文介绍了pyinstaller 不显示图像和图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了许多关于如何通过修改规范文件来包含图像和图标的教程,尽管我无法成功.我编写了一个程序,我想使用 pyinstaller 使其可执行并在其他计算机上运行它.pyinstaller 在主 .exe 文件中不包含图像和图标文件.当我在自己的电脑上运行编译后的 .exe 文件时,它工作得很好,但是当我尝试在其他计算机上运行相同的文件时,它会引发错误...提前致谢..下面是我的 .spec 文件代码和我的 python 脚本(部分)

I read many tutorials on how to include image and icons by modifying the spec file though I couldn't succeed.I wrote a program which I want to make executable using pyinstaller and run it on other computers. pyinstaller doesnot include image and icon files on the main .exe file. When I run the compiled .exe file on my own pc it works just fine but when I try to run the same file on other computer, it throws an error.. Please suggest me how do I do it, this is driving off my brain.. Thanks in advance.. below is my .spec file code and my python script(partial)

.spec 文件:

# -*- mode: python -*-
a = Analysis(['English-Nepali.py'],
             pathex=['C:\\Users\\User\\Desktop\\Dict'],
             hiddenimports=[],
             hookspath=None,
             runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='English-Nepali.exe',
          debug=False,
          strip=None,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=None,
               upx=True,
               name='English-Nepali')

使用图像和图标的部分程序,目录中存在ico和jpg文件:

part of the program where image and icon is used, both ico and jpg files are present in the directory:

class Demo2:
    def __init__(self, master):
        self.master = master
        self.master.geometry("640x250+200+200")
        master.resizable(False,False)
        self.master.title('About')
        self.img = Image.open(r"C:\Users\User\Desktop\Dict\rotunda.jpg")
        self.tetras = ImageTk.PhotoImage(self.img)

def main():

    root = tk.Tk()
    ex = Example(root)
    root.iconbitmap(r"C:\Users\User\Desktop\Dict\1.ico")
    root.resizable(False,False)
    root.mainloop()  

推荐答案

.ico &.jpg 文件位于 pyinstaller 创建的文件夹中.

Put the .ico & .jpg files in the folder that pyinstaller created.

这篇关于pyinstaller 不显示图像和图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆