如何将一整个python工程打包

发布网友 发布时间:2022-04-20 15:46

我来回答

2个回答

热心网友 时间:2022-04-18 07:08

1、下载并安装py2exe,可下载最新版本。

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 moles ***
*** parsing results ***
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
writing byte-compilation script 'e:\tmp\tmp1ecbcw.py'

热心网友 时间:2022-04-18 08:26

打包成可执行文件的话,py2exe是不行的,看名字就知道,那是打包python2的,它不支持python3,用pyinstaller可以打包python3,教程也很简单,搜下一行命令就能打包了。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com