不能让py2exe工作

时间:2017-02-22 15:21:56

标签: python python-3.x py2exe

现在我已经尝试将我的python应用程序打包为一个独立的可执行文件。我一直试图使用py2exe但它似乎从未发挥作用。

假设我们有机器A和机器B,我在机器A上构建程序并尝试在机器B上作为可执行文件运行。在尝试在机器B上运行的前几次尝试时它会说{{1}但我认为这归结为FATAL ERROR: Cannot load python library进程说py2exe已满:

1 missing module

然后我看到了这个问题Py2Exe "Missing Modules"并发现我需要安装 1 missing Modules ------------------ ? readline imported from cmd, code, pdb Building 'dist\workinghoursGUI.exe'. Building shared code archive 'dist\library.zip'. Copy c:\python34\python34.dll to dist Copy C:\Python34\DLLs\select.pyd to dist\select.pyd Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd Copy C:\Python34\DLLs\_tkinter.pyd to dist\_tkinter.pyd Copy DLL C:\Python34\MSVCR100.dll to dist\ Copy DLL C:\Python34\DLLs\tk86t.dll to dist\ Copy DLL C:\Python34\DLLs\tcl86t.dll to dist\ 所以我做了,然后pyreadline进程没有返回任何丢失的模块,如下所示:

py2exe

但现在在机器B上运行Building 'dist\workinghoursGUI.exe'. Building shared code archive 'dist\library.zip'. Copy c:\python34\python34.dll to dist Copy C:\Python34\lib\site-packages\win32\_win32sysloader.pyd to dist\_win32sysloader.pyd Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd Copy C:\Python34\DLLs\select.pyd to dist\select.pyd Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd Copy C:\Python34\DLLs\_tkinter.pyd to dist\_tkinter.pyd Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd Copy C:\Python34\lib\site-packages\win32\win32api.pyd to dist\win32api.pyd Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd Copy C:\Python34\lib\site-packages\win32\win32evtlog.pyd to dist\win32evtlog.pyd Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd Copy DLL C:\Python34\DLLs\tcl86t.dll to dist\ Copy DLL C:\Python34\MSVCR100.dll to dist\ Copy DLL C:\Python34\DLLs\tk86t.dll to dist\ Copy ExtensionDLL C:\Python34\pywintypes34.dll to dist\ 时,只显示输出.exe的窗口,而应用程序在机器A上正常运行

这是我的设置文件:

port>

并且我的程序中的导入都在python的标准版本中:

from distutils.core import setup
import py2exe,sys,os

setup(console=['workinghoursGUI.py'])
我可能做了一些明显错误的事情,但我无法解决问题,有谁知道我如何解决这个问题,或者我只是不得不放弃?

from tkinter import * from tkinter import ttk import tkinter as tk import tkinter.messagebox as tkm import datetime,os,time 文件夹如下所示:

dist folder

1 个答案:

答案 0 :(得分:2)

我终于使用这个问题py2exe - generate single executable file

让这个工作了

我发现我必须修改我的设置文件,现在看起来像这样:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')
#bundle files set to 2 because its a tkinter app
setup(
    options = {'py2exe': {'bundle_files': 2, 'compressed': True}},
    windows = [{'script': "workinghoursGUI.pyw"}],
    zipfile = None,
)

但是因为在我的代码中我使用的是os.path.dirname(os.path.realpath(__file__))py2exe并不支持__file__,我发现自己处于这个问题How do I get the path of the current executed file in Python?并使用ArtOfWarfare的答案来获取当前路径,是:

from inspect import getsourcefile
from os.path import abspath
...
abspath(getsourcefile(lambda:0))