我想从Python脚本中寻求帮助,我使用CustomTkinter,Iconipy库。
创建.exe文件后,我完成了此错误:from PIL import Image
from customtkinter import CTk, CTkFrame, CTkImage, CTkButton
from iconipy import IconFactory
def Create_Icon(Icon_Set: str, Icon_Name: str, Icon_Size: str, Theme_index: int) -> Image:
Icon_Fact = IconFactory(
icon_set = Icon_Set,
icon_size = 40,
font_size = 30,
font_color = "#FFFFFF",
outline_width = 0,
outline_color = None,
background_color = None,
background_radius = 0)
Icon_PIL = Icon_Fact.asPil(Icon_Name)
return Icon_PIL
def Get_CTk_Icon(Icon_Set: str, Icon_Name: str, Icon_Size: str) -> CTkImage:
Picture = CTkImage(
light_image = Create_Icon(Icon_Set=Icon_Set, Icon_Name=Icon_Name, Icon_Size=Icon_Size, Theme_index=0),
dark_image =Create_Icon(Icon_Set=Icon_Set, Icon_Name=Icon_Name, Icon_Size=Icon_Size, Theme_index=1),
size = (40, 40))
return Picture
def Get_Button_Icon(Frame: CTk|CTkFrame, Icon_Set: str, Icon_Name: str, Icon_Size: str, Button_Size: str) -> CTkFrame:
Frame_Button = CTkButton(
master = Frame,
width = 40,
height = 40,
corner_radius = 0,
border_width = 0,
bg_color = "transparent",
fg_color = "transparent",
hover = False,
anchor = "center",
text = "")
CTK_Image = Get_CTk_Icon(Icon_Set=Icon_Set, Icon_Name=Icon_Name, Icon_Size=Icon_Size)
Frame_Button.configure(image=CTK_Image, text="")
return Frame_Button
window = CTk()
Icon_Theme = Get_Button_Icon(Frame=window, Icon_Set="lucide", Icon_Name="sun-moon", Icon_Size="Header", Button_Size="Picture_Theme")
Icon_Theme.configure(text="")
Icon_Theme.pack(side="top", fill="none", expand=False, padx=5, pady=5)
# run
window.mainloop()
我在我只有的虚拟环境中使用anaconda:
# environment.yml
name: ENV-Iconipy_Pyinstaller
channels:
- defaults
- https://repo.anaconda.com/pkgs/main
- https://repo.anaconda.com/pkgs/msys2
- https://repo.anaconda.com/pkgs/r
dependencies:
- bzip2=1.0.8=h2bbff1b_6
- ca-certificates=2024.12.31=haa95532_0
- expat=2.6.4=h8ddb27b_0
- libffi=3.4.4=hd77b12b_1
- libmpdec=4.0.0=h827c3e9_0
- openssl=3.0.15=h827c3e9_0
- pip=24.2=py313haa95532_0
- python=3.13.2=hadb2040_100_cp313
- python_abi=3.13=0_cp313
- setuptools=75.8.0=py313haa95532_0
- sqlite=3.45.3=h2bbff1b_0
- tk=8.6.14=h0416ee5_0
- tzdata=2025a=h04d1e81_0
- vc=14.42=haa95532_4
- vs2015_runtime=14.42.34433=he0abc0d_4
- wheel=0.44.0=py313haa95532_0
- xz=5.6.4=h4754444_1
- zlib=1.2.13=h8cc25b3_1
- pip:
- altgraph==0.17.4
- customtkinter==5.2.2
- darkdetect==0.8.0
- iconipy==0.3.2
- packaging==24.2
- pefile==2023.2.7
- pillow==11.1.0
- pyinstaller==6.12.0
- pyinstaller-hooks-contrib==2025.1
- pywin32-ctypes==0.2.3
prefix: C:\Users\CZ011845\AppData\Local\miniconda3\envs\ENV-Iconipy_Pyinstaller
I仅通过“ conda install python”安装了Python,然后由PIP安装了这3个:
PIP安装CustomTkinter
run:conda激活env-iconipy_pyinstaller
con纠正项目路径C:\Users\moham\Desktop\mine\stack\Final_exe_file\exe>test.exe
Traceback (most recent call last):
File "test.py", line 48, in <module>
File "test.py", line 42, in Get_Button_Icon
File "test.py", line 25, in Get_CTk_Icon
File "test.py", line 11, in Create_Icon
File "iconipy\iconipy.py", line 259, in __init__
File "iconipy\iconipy.py", line 419, in _get_icon_set_version
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\moham\\AppData\\Local\\Temp\\_MEI73962\\iconipy\\assets\\lucide\\version.txt'
[PYI-5844:ERROR] Failed to execute script 'test' due to unhandled exception!
IS说Iconipy无法到达文件版本。txt.
FiLenotFoundError:[Errno 2]没有这样的文件或目录:'C:\ USERS \ MOHAM \ APPDATA \ local \ local \ temp \ _mei73962 \ iconipy ssets \ lucide ssets \ lucideersion.txtt'
为什么?
由于Pyinstaller并未将所有内容都放在您的EXE应用程序中。SOpyinstaller没有将内部文件如何解决?vers.txt
添加到您的exe内部文件,因此此错误出现。
随后,库将找到预期的文件。
如何做?在您的终端中使用此命令:
pyinstaller --noconfirm --onefile --console --add-data "C:\Python3-12-8\Lib\site-packages\iconipy;iconipy/" "C:\Users\moham\Desktop\mine\stack\test.py"