建立可执行Python3和PyQt
-
20-09-2019 - |
题
我建了一个相当简单的应用程序在Python3.1使用PyQt4.正在做我想要应用程序的分布式计算机不需要的那些安装。
我几乎完全关心的视窗平台,使我的目标是要有一个可执行的文件也许有些资源文件。dll在结束。
具有搜索时,我得出的结论,
- py2exe 只支持Python达到2.7版
- pyinstaller 只支持Python达到2.6版
- cx_Freeze 不能工作对我来说是因为我继续得到以下错误时,试图执行我成功地建立binary:
Y:\Users\lulz\build\exe.win32-3.1>system_shutdown.exe
Traceback (most recent call last):
File "Y:\Program Files (x86)\Python\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in exec(code, m.__dict__)
File "Y:/Users/lulz/Documents/Coding/Python3/projects/System Shutdown/system_shutdown.pyw", line 5, in from PyQt4 import QtCore
File "ExtensionLoader_PyQt4_QtCore.py", line 16, in AttributeError: 'NoneType' object has no attribute 'modules'
所以我的问题基本上是两个问题:
- 是否有另一种方式,但cx_Freeze建立的二进制文件用我配置?
- 如果不是,什么可能的cx_Freeze问题是什么?
我可以提供更多信息在第二个问题如果有必要,就像我呼吁cx_Freeze,我distutils来完成安装脚本等等。
谢谢你已经为你们的帮助和意见。
解决方案
你可以解决这个问题通过追加一行代码freeze.py 在你cx_Freeze包。
它描述了这里:http://www.mail-archive.com/cx-freeze-users@lists.sourceforge.net/msg00212.html
它的工作对我来说至少:)
干杯, Almar
其他提示
Python3.3和以后,有一个很好的决议:py2exe产生单一执行文件
安装py2exe:
pip install py2exe
然后添加一'your_script.py'文件,下面的'Make_exe.py'文件:
from distutils.core import setup
import py2exe, sys
class Make_exe():
def __init__(self, python_script):
sys.argv.append('py2exe')
setup(
console=[{'script': python_script}],
zipfile = None,
options={
'py2exe':
{
'bundle_files': 1,
'compressed': True,
# Add includes if necessary, e.g.
'includes': ['lxml.etree', 'lxml._elementpath', 'gzip'],
}
}
)
if __name__ == '__main__':
Make_exe('your_script.py')
如果你想使'your_script.py' 重建自己 为'your_script.exe' 每次运行它在蟒蛇, 你可以添加到其主要:
import subprocess
import sys
if __name__ == '__main__':
currentFile = sys.argv[0]
if currentFile.lower().endswith(".py"):
exitCode = subprocess.call("python Make_exe.py")
if exitCode==0 :
dirName = os.path.dirname(currentFile)
exeName = os.path.splitext(os.path.basename(currentFile))[0] + '.exe'
exePath = dirName + "/dist/" + exeName
cmd = [exePath] + sys.argv[1:]
print ("Executing command:\n %s" % cmd)
exitCode = subprocess.call(cmd)
sys.exit(exitCode)
else:
print ("This will be executed only within the new generated EXE File...")
不隶属于 StackOverflow