移动时Cx_freeze .exe不会工作

时间:2017-04-24 08:21:28

标签: python matplotlib cx-freeze

我从一组脚本中创建了一个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包含在build文件夹中也是如此。每当我从原始计算机运行它时,.exe运行正常,即使我从原始文件夹移动构建。我在64位Windows 10上使用python 3.6。对此的任何建议将不胜感激。如果需要更多信息,请与我们联系。

感谢。

1 个答案:

答案 0 :(得分:3)

我设法解决了这个问题,所以今后我们会找到有这个问题的人:可以通过从&#34; C:\ ProgramData \ Anaconda3 \ Library \ bin&#34;中复制以下文件来修复此问题。 (或&#34; ... \ Anaconda3 \ Library \ bin&#34;)到您的构建文件夹:

  • mkl_core.dll
  • mkl_intel_thread.dll
  • mkl_def.dll
  • libiomp5md.dll