iconipy和pyinstaller essue

问题描述 投票:0回答:1

我想从Python脚本中寻求帮助,我使用CustomTkinter,Iconipy库。

    Pyinstaller:
  • Https://pyinstaller.org/en/stable
  • iconimy:
  • https://iconipy.digidigital.de/iconipy.html
创建.exe文件后,我完成了此错误:

Error after runnig .exe file avter converting Myin.py 我的Python代码:

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
  1. PIP安装Iconipy
  2. PIP安装Pyinstaller
  3. 我将main.py与.exe(在Anaconda中)进行对话:

run:conda激活env-iconipy_pyinstaller

con纠正项目路径
    run:pyinstaller - 名称测试 - onedir-窗口main.py
  1. add路径和文件夹中的文件夹“ _ internal”(因为没有问题)
  2. Path:“ _ Internal/Iconipy/Assets/Lucide/”
  3. empty文件1:info.json
    emptyfile2:version.txt
  • 如果我在终端中运行代码是正确的,我会收到此窗口:

Sucessfull run through terminal这里的问题是关于Iconipy无法到达的内部路径和文件,

这是错误:
python icons pyinstaller
1个回答
0
投票
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将整个库添加到您的exe中。

随后,库将找到预期的文件。

如何做?

在您的终端中使用此命令: pyinstaller --noconfirm --onefile --console --add-data "C:\Python3-12-8\Lib\site-packages\iconipy;iconipy/" "C:\Users\moham\Desktop\mine\stack\test.py"

用您的道路来修复路径,这将使它起作用。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.