最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - iconipy and pyinstaller issue - Stack Overflow

programmeradmin3浏览0评论

I would like to ask you for help with creation of .exe file from python script where I use customtkinter, iconipy libraries.

  • pyinstaller:
  • iconimy: .html

After creation of .exe file I finished with this error:

My python code:

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()

I use anaconda for virtual environment where I have only:

# environment.yml

name: ENV-Iconipy_Pyinstaller
channels:
  - defaults
  - 
  - 
  - 
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 installed only python by "conda install python" and then these 3 by pip:

  1. pip install customtkinter
  2. pip install iconipy
  3. pip install pyinstaller

and I convers the main.py to .exe (in Anaconda):

  1. run: conda activate ENV-Iconipy_Pyinstaller
  2. cd to correct project path
  3. run: pyinstaller --name Test --onedir --windowed main.py
  4. Add path and files into folder "_internal" (because without that there are issues)
  • Path: "_internal/iconipy/assets/lucide/"
  • Empty file1: info.json
  • Empty file2: version.txt

If I run code in terminal it is correct and I receive this window:

I would like to ask you for help with creation of .exe file from python script where I use customtkinter, iconipy libraries.

  • pyinstaller: https://pyinstaller./en/stable
  • iconimy: https://iconipy.digidigital.de/iconipy.html

After creation of .exe file I finished with this error:

My python code:

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()

I use anaconda for virtual environment where I have only:

# environment.yml

name: ENV-Iconipy_Pyinstaller
channels:
  - defaults
  - https://repo.anaconda/pkgs/main
  - https://repo.anaconda/pkgs/msys2
  - https://repo.anaconda/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 installed only python by "conda install python" and then these 3 by pip:

  1. pip install customtkinter
  2. pip install iconipy
  3. pip install pyinstaller

and I convers the main.py to .exe (in Anaconda):

  1. run: conda activate ENV-Iconipy_Pyinstaller
  2. cd to correct project path
  3. run: pyinstaller --name Test --onedir --windowed main.py
  4. Add path and files into folder "_internal" (because without that there are issues)
  • Path: "_internal/iconipy/assets/lucide/"
  • Empty file1: info.json
  • Empty file2: version.txt

If I run code in terminal it is correct and I receive this window:

Share Improve this question edited Feb 14 at 22:21 Jan Vaško asked Feb 14 at 22:15 Jan VaškoJan Vaško 718 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

the problem here is about internal paths and files that iconipy can not reach,

this is the error :

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 says the iconipy can not reach the file version.txt.

FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\moham\AppData\Local\Temp\_MEI73962\iconipy\assets\lucide\version.txt'

Why?

because pyinstaller did not put everything inside the library to your exe application.

so pyinstaller did not add the internal file version.txt to your exe internal files, and because of that this error appears.

how to solve it ?

to solve this problem you have to add the entire library yourself, as an additional folder to your exe application.

and this will force pyinstaller to add the entire library to your exe.

after that, the library will find the intended file.

how to do it ?

do this command in your terminal:

pyinstaller --noconfirm --onefile --console --add-data "C:\Python3-12-8\Lib\site-packages\iconipy;iconipy/" "C:\Users\moham\Desktop\mine\stack\test.py"

replace the paths with your paths, and this will make it work.

Soved by adding iconipy "assets" folder into "_internal" as whole folder inside pyinstaller .spec file + add "iconipy" as hiddenimports:

发布评论

评论列表(0)

  1. 暂无评论