Cx_freeze .exe 在移动时无法工作
Posted
技术标签:
【中文标题】Cx_freeze .exe 在移动时无法工作【英文标题】:Cx_freeze .exe wont work when moved 【发布时间】:2017-04-24 08:21:27 【问题描述】:我从一组脚本中制作了一个 cx_freexe .exe,它在原始构建文件夹中运行良好。然而,当我将它移到我们的分析计算机上时,我得到了以下错误:
C:\Program Files\Davidek\Davidek beta 1.2.0>Davidek.exe
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__start
up__.py", line 12, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console
.py", line 24, in <module>
File "Davidek.py", line 11, in <module>
File "C:\Users\Max\Scilifelab\Projects\Master thesis\Davidek\Code\TICwriter.py
", line 7, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line
122, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook.py", line 32
, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 142,
in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 1
3, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line
8, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\type_check.py", lin
e 11, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line
14, in <module>
ImportError: DLL load failed: The specified module could not be found.
C:\Program Files\Davidek\Davidek beta 1.2.0>PAUSE
Press any key to continue . . .
这是似乎导致问题的代码“TICwriter.py”:
import matplotlib
#Forces matplotlib to not show plot:
matplotlib.use('Agg')
import matplotlib.pyplot as pl
import os
def TICwriter(TIC, dataFile, saveDirectory):
""" Saves a TIC file as a .png in the specified saveDirectory under a
output subdirectory.
"""
#Create savename from data file name:
savefile = dataFile.split('/')[-1].split('.')[0] + '_TIC.png'
#Create ouput directory:
saveDirectory = os.path.join(saveDirectory, 'output/')
os.makedirs(os.path.dirname(saveDirectory), exist_ok=True)
#Plot figure:
Plot = pl.figure()
TICplot = Plot.add_subplot(111)
TICplot.plot([d[0] for d in TIC], [d[1] for d in TIC])
#Save and close plot:
pl.savefig(saveDirectory + savefile)
pl.close(Plot)
在我看来,matplotlib 导致了问题,因为错误发生在第 7 行:
import matplotlib
我的构建脚本如下所示:
import sys
from os import environ
from os.path import dirname
from cx_Freeze import setup, Executable
import scipy
scipy_path = dirname(scipy.__file__)
# Set the TCL and TK library explicitly (it seems like the python 3.6 causes
# errors otherwise):
environ['TCL_LIBRARY'] = r'C:\ProgramData\Anaconda3\tcl\tcl8.6'
environ['TK_LIBRARY'] = r'C:\ProgramData\Anaconda3\tcl\tk8.6'
#Inclusion of dll files to fix tkinter import:
include_files = [r'C:\ProgramData\Anaconda3\DLLs\tcl86t.dll',
r'C:\ProgramData\Anaconda3\DLLs\tk86t.dll',
scipy_path]
#Inclusion of modules that need to be explicitly imported for some reason:
packages = []#['pyteomics']
#Dependencies that are not implicitly detected:
build_exe_options = 'includes': ['numpy.core._methods', 'numpy.lib.format', 'numpy.matlib'],
'excludes': [],
'include_files': include_files,
'packages': packages
# GUI applications require a different base on Windows (the default is for a
# console application).
base = "Console"
#if sys.platform == 'win32':
# base = 'Win32GUI'
setup( name = 'Davidek beta 1.1.1',
version = '1.1.1',
options = 'build_exe': build_exe_options,
executables = [Executable('Davidek.py', base=base)])
在我看来,.exe 试图从创建可执行文件的计算机的原始文件夹中查找 matplotlib 模块,即使 matplotlib 包含在构建文件夹中。每当我从原始计算机运行 .exe 时,它运行良好,即使我从原始文件夹中移动构建也是如此。我在 64 位 Windows 10 上使用 python 3.6。对此的任何建议将不胜感激。如果需要更多信息,请告诉我。
谢谢。
【问题讨论】:
【参考方案1】:我设法修复了它,所以我们在这里为将来遇到此问题的任何人提供帮助:可以通过从“C:\ProgramData\Anaconda3\Library\bin”(或“.. .\Anaconda3\Library\bin") 到你的构建文件夹:
mkl_core.dll mkl_intel_thread.dll mkl_def.dll libiomp5md.dll【讨论】:
以上是关于Cx_freeze .exe 在移动时无法工作的主要内容,如果未能解决你的问题,请参考以下文章
使用 cx_Freeze 时出现问题:“无法导入名称 'tf2'”
cx_Freeze 不工作 - 没有名为 cx_Freeze 的模块