cx_freeze打包成exe的时候,如果用到了scipy,需要进入cx_freeze文件夹里面,将hooks.py的第550多行的代码finder.IncludePackage("scipy.lib")
改为finder.IncludePackage("scipy._lib")
。
不过运行程序的时候,可能会出现
ImportError: No module named 'scipy.spatial.ckdtree'
这时候需要进入打包后的文件夹里面,找到scipy\spatial\cKDTree.cp35-win32.pyd,将其改为ckdtree.cp35-win32.pyd
如果用到matplotlib,或是其他关于tkinter的包,需要在setup里面手动设置
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# os.environ['TCL_LIBRARY'] = r'C:\Users\Davidham3\Desktop\regression\python3.5\tcl\tcl8.6'
# os.environ['TK_LIBRARY'] = r'C:\Users\Davidham3\Desktop\regression\python3.5\tcl\tk8.6'
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["tkinter", "os", "numpy", "pandas", "sklearn", "matplotlib", "scipy"],
"includes": ["tkinter", "scipy"],
'include_files':[
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
]}