python 用cx_Freeze打包程序詳細解讀setup.py

最近在學習用python開發深度學習工具,發現使用cx_Freeze對程序進行打包時,採用構建setup.py的時候出現很多不清楚的地方,現在詳細說明setup.py文件的內容

os.environ['TCL_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tk8.6"

include_files = [r"C:\ProgramData\Anaconda3\DLLs\tcl86t.dll",
                 r"C:\ProgramData\Anaconda3\DLLs\tk86t.dll",
                ]

1、上面的兩個庫文件都在python安裝路徑下可以找到,python運行時候依賴的庫 

options = {
    'build_exe': {
        'includes': 'atexit' ,
        'include_files': include_files,
        'packages':['cv2','numpy','xml.etree','tensorflow','libs.label_name_dict']
    }
}

2、options是打包程序import的包,其中 'cv2','numpy','xml.etree','tensorflow'是安裝的python包,'libs.label_name_dict'是當前項目裏面的庫,但是之前這麼寫,build的時候會提示找不到libs庫,這是因爲python沒有將當前路徑設置成系統路徑,需要添加設置:sys.path.append(r'../')

           

executables = [
    Executable('new_gui_temp.py', base=base),
]

3、executables = [Executable('new_gui_temp.py', base=base),]是打包的py文件,可以有多個

import sys
from cx_Freeze import setup, Executable
import os
sys.path.append(r'../')

os.environ['TCL_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tk8.6"

include_files = [r"C:\ProgramData\Anaconda3\DLLs\tcl86t.dll",
                 r"C:\ProgramData\Anaconda3\DLLs\tk86t.dll",
                ]

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

options = {
    'build_exe': {
        'includes': 'atexit' ,
        'include_files': include_files,
        'packages':['cv2','numpy','xml.etree','tensorflow','libs.label_name_dict']
    }
}

executables = [
    Executable('new_gui_temp.py', base=base),
]

setup(name='education',
      version='0.1',
      description='ImagePre software',
      options=options,
      executables=executables
      )

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章