网站直播间怎么做,网站ip和uv,此网站无法提供安全连接 建设银行,扁平网站欣赏本文基于windows 7 python 3.4 把python程序打包成exe#xff0c;比较好用的库是py2exe 其操作步骤是: -- 编写python程序 -- 再额外编写一个导入了py2exe的python脚本(不妨如#xff1a;setup.py)存在同一目录下 -- 运行这个脚本#xff0c;打包生成的exe文件… 本文基于windows 7 python 3.4 把python程序打包成exe比较好用的库是py2exe 其操作步骤是: -- 编写python程序 -- 再额外编写一个导入了py2exe的python脚本(不妨如setup.py)存在同一目录下 -- 运行这个脚本打包生成的exe文件保存在一个dist目录下 三个例子 1.命令行 2.GUI (tkinter) 3.GUI (pyqt5) 1. 命令行 # hello.pyprint(你好世界) # setup.pyfrom distutils.core import setup
import py2exe
import sys#this allows to run it with a simple double click.
sys.argv.append(py2exe)py2exe_options {compressed: 1,optimize: 2,ascii: 0,bundle_files: 1, # 其中bundle_files有效值为# 3 (默认)不打包。# 2 打包但不打包Python解释器。# 1 打包包括Python解释器。
setup(name console demo,version 1.0,console [hello.py,], # console 命令行执行程序# windows 窗口执行程序zipfile None,options {py2exe: py2exe_options}) 现在有两个文件了 再进到目录运行上面这个setup.py脚本亦可双击运行该脚本 然后发现多了一个dist目录 可以发现dist目录下生成了一个hello.exe文件 再在命令行下执行hello.exe 2. GUI (tkinter) # hello.pyimport tkinter as tkroot tk.Tk()tk.Label(root, text你好世界).pack(ipadx100, ipady50)root.mainloop() # setup.pyfrom distutils.core import setup
import py2exe
import sys#this allows to run it with a simple double click.
sys.argv.append(py2exe)py2exe_options {compressed: 1,optimize: 2,ascii: 0,bundle_files: 2, # 修改2打包但不打包Python解释器
setup(name tk demo,version 1.0,windows [hello.py,], # 修改windowszipfile None,options {py2exe: py2exe_options}) 说明 对tkinter打包 bundle_files 必须为 2若是1会报错 进到目录运行上面这个setup.py脚本 可以发现dist目录下生成了一个hello.exe文件和另外几个dll文件 双击运行出现窗口 3. GUI (pyqt5) # hello.py
from PyQt5 import QtWidgets, QtCore, QtGui # 不管是否用到只要是打包成exe都要导入import sysapp QtWidgets.QApplication(sys.argv)root QtWidgets.QWidget()
root.resize(200,100)
QtWidgets.QLabel(root, text你好世界)
root.show()sys.exit(app.exec_()) 说明不管是否用到都要导入 from PyQt5 import QtWidgets, QtCore, QtGui # setup.py
from distutils.core import setup
import py2exe
import sys#this allows to run it with a simple double click.
sys.argv.append(py2exe)py2exe_options {includes: [sip], # PyQt5专有#dll_excludes: [MSVCP90.dll,], # 鱼友论坛说这句必须有我的没有也可以compressed: 1,optimize: 2,ascii: 0,bundle_files: 1, #这里还是1}setup(name pyqt5 hello,version 1.0,windows [hello.py,], # 窗口执行# PyQt5专有data_files[(,[rC:\Python34\Lib\site-packages\PyQt5\libEGL.dll]),(platforms,[rC:\Python34\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll])],zipfile None,options {py2exe: py2exe_options}) 说明对于pyqt5下面两个是必须的 ①includes: [sip] ②data_files[(,[rC:\Python34\Lib\site-packages\PyQt5\libEGL.dll]),(platforms, [rC:\Python34\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll])] 进到目录运行上面这个setup.py脚本 可以发现dist目录下生成了一个hello.exe文件和另外几个dll文件 双击运行出现窗口 本文转自罗兵博客园博客原文链接http://www.cnblogs.com/hhh5460/p/5388204.html如需转载请自行联系原作者