gpt4 book ai didi

python - 移动时 Cx_freeze .exe 将无法工作

转载 作者:行者123 更新时间:2023-11-30 22:38:22 24 4
gpt4 key购买 nike

我从一组脚本中制作了一个 cx_freeexe .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。对此的任何建议将不胜感激。如果需要更多信息,请告诉我。

谢谢。

最佳答案

我设法修复了它,所以我们为将来遇到此问题的任何人提供帮助:可以通过从“C:\ProgramData\Anaconda3\Library\bin”(或“.. .\Anaconda3\Library\bin") 到您的构建文件夹:

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

关于python - 移动时 Cx_freeze .exe 将无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43583089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com