python程序打包成.exe----pyinstaller工具

摘要:
在WIN7上打包并将其放在XP上。目录无法打开,单个文件正常。

1. 环境

windows

2. 安装

准备文件:PyWin32 or pypiwin32 

运行如下安装命令:  pip install pyinstaller==3.0

不要使用3.2版本,编译完成后会报Runtime Error, R6034错误.

3.0版本无此问题。

3. 打包

把.py或.pyw文件拷贝到pyinstaller所在目录

执行命令: pyinstaller -F xxx.py ,会把生成的文件自动放到dist目录下,文件名默认为xxx.exe。

常用参数说明:

-F:把所有文件打包成一个.exe。

-D:把所有文件打包成一个目录,里面包含可执行文件和所需库等其他文件。

-n NAME:重新命名可执行文件。

-w:打开打包后的程序,将不会弹出命令行窗口。

4. 单独文件和目录比较

目录的比单个文件尺寸要大;

目录的比单个文件打开速度要快。

在WIN7上打包,放到XP上,目录的打开失败,单个文件正常。

详细参数说明见文档

http://pythonhosted.org/PyInstaller/#general-options

General Options

-h, --helpshow this help message and exit
-v, --versionShow program version info and exit.
--distpath=DIRWhere to put the bundled app (default: ./dist)
--workpath=WORKPATH
 Where to put all the temporary work files, .log, .pyz and etc. (default: ./build)
-y, --noconfirm
 Replace output directory (default: SPECPATH/dist/SPECNAME) without asking for confirmation
--upx-dir=UPX_DIR
 Path to UPX utility (default: search the execution path)
-a, --asciiDo not include unicode encoding support (default: included if available)
--cleanClean PyInstaller cache and remove temporary files before building.
--log-level=LOGLEVEL
 Amount of detail in build-time console messages (default: INFO, choose one of DEBUG, INFO, WARN, ERROR, CRITICAL)

What to generate

-F, --onefileCreate a one-file bundled executable.
-D, --onedirCreate a one-folder bundle containing an executable (default)
--specpath=DIRFolder to store the generated spec file (default: current directory)
-n NAME--name=NAME
 Name to assign to the bundled app and spec file (default: first script's basename)

What to bundle, where to search

-p DIR--paths=DIR
 A path to search for imports (like using PYTHONPATH). Multiple paths are allowed, separated by ':', or use this option multiple times
--hidden-import=MODULENAME
 Name an import not visible in the code of the script(s). This option can be used multiple times.
--additional-hooks-dir=HOOKSPATH
 An additional path to search for hooks. This option can be used multiple times.
--runtime-hook=RUNTIME_HOOKS
 Path to a custom runtime hook file. A runtime hook is code that is bundled with the executable and is executed before any other code or module to set up special features of the runtime environment. This option can be used multiple times.
--exclude-module=EXCLUDES
 Optional module or package (his Python names,not path names) that will be ignored (as thoughit was not found).This option can be used multiple times.
--key=KEYThe key used to encrypt Python bytecode.

How to generate

-d, --debugTell the bootloader to issue progress messages while initializing and starting the bundled app. Used to diagnose problems with missing imports.
-s, --stripApply a symbol-table strip to the executable and shared libs (not recommended for Windows)
--noupxDo not use UPX even if it is available (works differently between Windows and *nix)

Windows and Mac OS X specific options

-c, --console, --nowindowed
 Open a console window for standard i/o (default)
-w, --windowed, --noconsole
 Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle.This option is ignored in *NIX systems.
-i <FILE.ico or FILE.exe,ID or FILE.icns>--icon=<FILE.ico or FILE.exe,ID or FILE.icns>
 FILE.ico: apply that icon to a Windows executable. FILE.exe,ID, extract the icon with ID from an exe. FILE.icns: apply the icon to the .app bundle on Mac OS X

Windows specific options

--version-file=FILE
 add a version resource from FILE to the exe
-m <FILE or XML>--manifest=<FILE or XML>
 add manifest FILE or XML to the exe
-r <FILE[,TYPE[,NAME[,LANGUAGE]]]>--resource=<FILE[,TYPE[,NAME[,LANGUAGE]]]>
 Add or update a resource of the given type, name and language from FILE to a Windows executable. FILE can be a data file or an exe/dll. For data files, at least TYPE and NAME must be specified. LANGUAGE defaults to 0 or may be specified as wildcard * to update all resources of the given TYPE and NAME. For exe/dll files, all resources from FILE will be added/updated to the final executable if TYPE, NAME and LANGUAGE are omitted or specified as wildcard *.This option can be used multiple times.
--uac-adminUsing this option creates a Manifest which will request elevation upon application restart.
--uac-uiaccessUsing this option allows an elevated application to work with Remote Desktop.

Windows Side-by-side Assembly searching options (advanced)

--win-private-assemblies
 Any Shared Assemblies bundled into the application will be changed into Private Assemblies. This means the exact versions of these assemblies will always be used, and any newer versions installed on user machines at the system level will be ignored.
--win-no-prefer-redirects
 While searching for Shared or Private Assemblies to bundle into the application, PyInstaller will prefer not to follow policies that redirect to newer versions, and will try to bundle the exact versions of the assembly.

免责声明:文章转载自《python程序打包成.exe----pyinstaller工具》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇原生JS获取HTML DOM元素的方法----------c排序算法时间复杂度的下界下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

windows 常用命令行操作

目录操作 >pwd 打印当前工作目录,通过此关键词可以查看当前所处的路径 >cd 更改目录,用于多个目录之间的切换 具体输入: cd 目录名 cd 目录名/子目录名(可通过此方式到达最底层的目录) cd ~ (返回home目录) cd ..(返回上一级目录) cd ../..(返回上两级目录) cd 盘符名:(不同盘符间跳转,cd 后面跟上路...

Python文件读写、StringIO和BytesIO

1 IO的含义 在计算机中,IO是Input/Output的简写,也就是输入和输出。 由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘、网络等,就需要IO接口。 比如你访问百度首页,浏览器就需要通过网络IO获取网页。浏览器先会发送请求给百度服务器,告诉它想要的html网址,这个动作是往外发数据,叫Out...

解决python3.5无法导入cv2.so的问题

问题描述: 在python3.5环境中导入cv2报错,在python2.7中正常。注:命令行的前缀RL_2018HW是python3.5的环境。 (RL_2018HW) gordon@gordon-5577:$ python Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609...

配置c#环境变量

1. 首先 ,写一个后缀名为.cs的文件(用来编译) 2.找到桌面图标计算机 → 右键属性 → 高级系统设置 → 环境变量(在靠下面) → 先看【用户变量】里是否有 【Path】 → 没有去【全局变量】里找 → 找到之后,点击【编辑】 →在最后加一个分号【;】然后把我们文件的路径加上 → 点击【确定】,然后关闭。。 3.csc编译器位置:安装完在c盘的【w...

安装dlib C++

环境 Ubuntu18.04 dlib19 下载安装 下载 从github下载 dlib git clone https://github.com/davisking/dlib.git 安装 在dlib目录下, 依次执行。 mkdir build; cd build; cmake .. ; cmake --build . Python使用 pyt...

python读取pdf文件

pdfplumber简介 Pdfplumber是一个可以处理pdf格式信息的库。可以查找关于每个文本字符、矩阵、和行的详细信息,也可以对表格进行提取并进行可视化调试。 文档参考https://github.com/jsvine/pdfplumber pdfplumber安装 安装直接采用pip即可。命令行中输入 pip install pdfplumber...