Python Pyinstaller关于图标和写入捆绑文件的问题
我正在使用Python 3.6.8和Linux Ubuntu 我有一个icon.ico图像,我想将其嵌入Pyinstaller中的exe文件中。 我试过了Python Pyinstaller关于图标和写入捆绑文件的问题,python,pyinstaller,Python,Pyinstaller,我正在使用Python 3.6.8和Linux Ubuntu 我有一个icon.ico图像,我想将其嵌入Pyinstaller中的exe文件中。 我试过了 pyinstaller -F -i= 'icon.ico' main.py and pyinstaller -F --icon= 'icon.ico:.' main.py 我尝试了各种各样的方法,但我无法让它发挥作用 我基本上有一个tkinter应用程序,我想从中创建一个exe…我已经创建了一个png文件,将其转换为图标并尝试加载它,但
pyinstaller -F -i= 'icon.ico' main.py and
pyinstaller -F --icon= 'icon.ico:.' main.py
我尝试了各种各样的方法,但我无法让它发挥作用
我基本上有一个tkinter应用程序,我想从中创建一个exe…我已经创建了一个png文件,将其转换为图标并尝试加载它,但我不确定它是否可以完成…是否有方法将image.ico分配给应用程序?或者更改它们,我知道有一种方法可以从.desktop…下载的软件是如何做到的
这是我正在使用的内部代码:
import os, sys
from con import * # this is just a configuration file that has g='play' in it.
import subprocess
def resource_path(relative_path):
if getattr(sys, 'frozen', False):
bundle_dir = sys._MEIPASS # for --onefile
# bundle_dir = path.dirname(path.abspath(sys.executable)) # for --onedir
else:
bundle_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(bundle_dir, relative_path)
resource_path('data/bitbud.ico')
basedir = getattr(sys, "_MEIPASS", os.path.realpath(os.path.dirname(__file__)))
file=os.path.join(basedir, 'data/bell.mp3')
file2=os.path.join(basedir, 'data/testfile2.txt')
file3=os.path.join(basedir, 'data/bitbud.ico')
f=open('testfile1','w')
f.write('This has worked')
f.close()
f=open(file2,'a')
f.write('append also works')
f.close()
#if 'play' == g:
try:
subprocess.call(['/usr/bin/cvlc',file],timeout=6)
except:
pass
f1=open(file2,'r')
f=open('testfile3','w')
readit='The app has inside it:' +f1.read()
f.write(readit)
f.close()
f1.close()
给你的电话:D
Pyinstaller
后编辑some.spec
文件,添加如下参数:最好将第二个问题与此问题分开,否则其他人很难在SOI中搜索。我假设,您想要添加图标的原因是,生成的可执行文件使用桌面上的图标,而不是默认图标。我说得对吗?你想让它在Linux上运行吗?请确认并调整您的问题生成的exe使用的是通用图标…因此我创建了一个png,将其转换为ico,并尝试使用pyinstaller加载到exe…是否有其他方法将图标加载到exe?在Linux Ubuntu中,如果您打开
.spec
文件并转到底部的BUNDLE部分,您可以尝试在那里手动添加图标文件名。或者你可以看到你一直试图添加图标的方式是否被添加到那里。我正在使用Linux,这可以吗?您好,请检查我的完整代码和视频。我将代码放在下面的问题和视频中
def resource_path(relative_path):
if getattr(sys, 'frozen', False):
bundle_dir = sys._MEIPASS # for --onefile
# bundle_dir = path.dirname(path.abspath(sys.executable)) # for --onedir
else:
bundle_dir = path.dirname(path.abspath(__file__))
return path.join(bundle_dir, relative_path)
---
resource_path('assets/file.jpg')
a = Analysis(
...
datas=[('path/to/file.jpg', 'assets')]
...
...
exe = EXE(
...
icon='path/to/icon.ico')