无法让 py2exe 工作 [英] cant get py2exe to work

查看:63
本文介绍了无法让 py2exe 工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很长时间以来,我一直在尝试将我的 Python 应用程序打包为独立的可执行文件.我一直在尝试使用 py2exe 但它似乎从未奏效.

假设我们有机器 A 和机器 B,我在机器 A 上构建程序并尝试在机器 B 上作为可执行文件运行.在尝试在机器 B 上运行的前几次尝试中,它会说 FATAL错误:无法加载 python 库 但我认为这归结为 py2exe 进程说 1 missing module full:

 1 缺少模块------------------?从cmd、code、pdb导入的readline构建dist\workinghoursGUI.exe".构建共享代码存档dist\library.zip".复制 c:\python34\python34.dll 到 dist复制 C:\Python34\DLLs\select.pyd 到 dist\select.pyd复制 C:\Python34\DLLs\_lzma.pyd 到 dist\_lzma.pyd复制 C:\Python34\DLLs\_socket.pyd 到 dist\_socket.pyd复制 C:\Python34\DLLs\unicodedata.pyd 到 dist\unicodedata.pyd复制 C:\Python34\DLLs\_bz2.pyd 到 dist\_bz2.pyd复制 C:\Python34\DLLs\pyexpat.pyd 到 dist\pyexpat.pyd复制 C:\Python34\DLLs\_hashlib.pyd 到 dist\_hashlib.pyd复制 C:\Python34\DLLs\_ssl.pyd 到 dist\_ssl.pyd复制 C:\Python34\DLLs\_ctypes.pyd 到 dist\_ctypes.pyd复制 C:\Python34\DLLs\_tkinter.pyd 到 dist\_tkinter.pyd将 DLL C:\Python34\MSVCR100.dll 复制到 dist\将 DLL C:\Python34\DLLs\tk86t.dll 复制到 dist\将 DLL C:\Python34\DLLs\tcl86t.dll 复制到 dist\

然后我看到了这个问题

解决方案

我终于用这个问题解决了这个问题 py2exe - 生成单个可执行文件

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

from distutils.core 导入设置导入 py2exe、sys、ossys.argv.append('py2exe')#bundle 文件设置为 2,因为它是一个 tkinter 应用程序设置(options = {'py2exe': {'bundle_files': 2, 'compressed': True}},windows = [{'script': "workinghoursGUI.pyw"}],zipfile = 无,)

但是因为在我的代码中我使用了 os.path.dirname(os.path.realpath(__file__)) 并且 py2exe 不支持 __file__,我发现自己在这个问题 如何在 Python 中获取当前执行文件的路径? 并使用 ArtOfWarfare 的答案获取当前路径,即:

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

for ages now i have been trying to package my python applications up as a stand alone executable. i have been attempting to use py2exe but it has never seemed to work.

lets say we have machine A and machine B, i build the program on machine A and try to run as an executable on machine B. on the first few attempts when trying to run on machine B it would say FATAL ERROR: Cannot load python library but i thought that was down to the py2exe process saying 1 missing module full:

  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\

then i saw this question Py2Exe "Missing Modules" and found out i needed to install pyreadline so i did, then the py2exe process didnt return any missing modules like so:

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\

but now on machine B when the .exe is run a window with just the output port> is shown while the application runs fine on machine A

this is my setup file:

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

setup(console=['workinghoursGUI.py'])

and the imports in my program are all in the standard release of python which are:

from tkinter import *
from tkinter import ttk
import tkinter as tk
import tkinter.messagebox as tkm
import datetime,os,time

im probably doing something obviously wrong but i cant work out what, does anyone know how i can resolve this issue or am i just going to have to give up?

the dist folder looks like this:

解决方案

i have finally gotten this to work, using this question py2exe - generate single executable file

i found out i had to modify my setup file which now looks like this:

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,
)

but then because in my code i was using os.path.dirname(os.path.realpath(__file__)) and py2exe doesnt support __file__, i found myself on this question How do I get the path of the current executed file in Python? and used ArtOfWarfare's answer to get the current path, which is:

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

这篇关于无法让 py2exe 工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆