
2、编写安装脚本,比较简单,不过多解释,如下:
Screenshot_setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
includes = ["encodings", "encodings.*"]
data_files = ['CameraDll.dll']
options = {"py2exe"陪销肆:
{ "compressed": 1,
"optimize": 2,
"bundle_files": 1,
"includes": includes
}
}
setup(
version = "1.0",
description = "Screenshot Tool",
name = "Screenshot Tool",
options = options,
zipfile=None,
data_files = data_files,
console=[{"script": "Screenshot.py", "icon_resources": [(1, "Screenshot.ico")] }]
)
各参数含义见第5小节或执行python命令行下执行help(py2exe)查看。
3、打包程序:斗渗
a、将要找包的程序、文件和打包脚本放在同一目录下,如下:
E:\tmp\pyexe_tmp>tree /F
文件夹 PATH 列表
卷序列号码为 0007F240 101F:F68D
E:.
CameraDll.dll
screenshot.ico
Screenshot.py
screenshot_setup.py
没有子文件夹
E:\tmp\pyexe_tmp>
b、执行打包脚本:
E:\tmp\pyexe_tmp>python screenshot_setup.py py2exe
python screenshot_setup.py py2exe
running py2exe
creating E:\tmp\pyexe_tmp\build
creating E:\tmp\pyexe_tmp\build\bdist.win32
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
creating E:\tmp\芦轿pyexe_tmp\build\bdist.win32\winexe\bundle-2.6
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\temp
creating E:\tmp\pyexe_tmp\dist
*** searching for required modules ***
*** parsing results ***
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
writing byte-compilation script 'e:\tmp\tmp1ecbcw.py'
一、安装pyinsatller打开命令行窗口,输入如下指令pip3 install pyinstaller
然后静待pyinstaller自动安装好
二、旁迟使用pyinstaller打包Python程序
在你的Python程序文件夹上(不点进去)按住shift并且右键,在d出的选项中点击"在此处打开命令行窗口"或者“在此处打开PowerShell窗口”或者先进入命令行窗口,然后使用cd指令进入程序文件夹,示例:
cd G:\工程储存\Python工程\love
输入以下指令,开始打包
pyinstaller -F -w (-i icofile) filename
filename表示你的Python程序文件名
-w 表示隐藏程序运行时的命令行窗口(不加-w会有黑色窗口)
括号内的为可选参数,-i icofile表示给程毁尘序加上图标,图标必须为.ico格式icofile表示图标的位置,建议直接放在程序文件夹里面,这样子打包的时候直接写文件名就好输入完成,按回车,就会开始自动打包了,
第一次打包过程可能运余李比较缓慢输入
示例:pyinstaller -F -w -i favicon love.py
然后我们进入到程序目录里面会再看到一个名称为dist目录,打包好的exe程序就在里面
用pyinstaller,很容易就能实现,步骤如下:下载pyinstaller包,(我可以安装包发给你),把pyinstaller解压到任意路径后
1.开始->运行->cmd->回车
2.把路径改为pyinstaller所在的路径。比如pyinstaller在D盘罩姿,则输入“D:”(不包括“下同)回车,再输入”cd pyinstaller”回车乎卜
3.把你要打包的.py文件和执行文件所需要的文件复制到你解压的文件夹中(假如你要打包hello.py)
4.输入“Configure.py”回车
5.输入“Makespec.py hello.py”回车,正确的话会产生一个hello文件夹,把这个文件夹你的hello.spec文件复制到跟hello.py一物顷绝个目录里
6.输入“Build.py hello.spec”回车,正确执行后会在当前目录产生几个文件夹,在dist文件夹里的东西就是我们所需要的,最后记得把所有程序hello.py所需的文件拷到dist文件夹里。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)