使用pyinstaller将python文件打包成exe文件

pyinstaller官方网页:http://www.pyinstaller.org/

官方文档:https://pyinstaller.readthedocs.io/en/stable/

pyinstaller支持Python 2.7和Python 3.3+版本,并且支持Windows(XP+)、Mac OS X(10.7+)和Linux,但是只能在对应的系统编译对应的程序。

 

1、pyinstaller安装

在cmd(命令提示符)中直接安装

1 pip install pyinstaller

等待pip自动下载pyinstaller、pefile、pypiwin32、future共四个文件并自动安装,安装完成后输入

1 pyinstaller

会输出pyinstaller的使用方法如下:

 1 usage: pyinstaller-script.py [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
 2                              [-p DIR] [--hidden-import MODULENAME]
 3                              [--additional-hooks-dir HOOKSPATH]
 4                              [--runtime-hook RUNTIME_HOOKS]
 5                              [--exclude-module EXCLUDES] [--key KEY] [-d] [-s]
 6                              [--noupx] [-c] [-w]
 7                              [-i <FILE.ico or FILE.exe,ID or FILE.icns>]
 8                              [--version-file FILE] [-m <FILE or XML>]
 9                              [-r RESOURCE] [--uac-admin] [--uac-uiaccess]
10                              [--win-private-assemblies]
11                              [--win-no-prefer-redirects]
12                              [--osx-bundle-identifier BUNDLE_IDENTIFIER]
13                              [--distpath DIR] [--workpath WORKPATH] [-y]
14                              [--upx-dir UPX_DIR] [-a] [--clean]
15                              [--log-level LEVEL] [--upx UPX]
16                              scriptname [scriptname ...]
17 pyinstaller-script.py: error: the following arguments are required: scriptname

 

2、pyinstaller使用

直接在CMD中输入命令:

1 pyinstaller -F -w E:\Programer\Python\scraping\demo3.py

在经过一系列的信息和警告输出后完成,会提示出生成的exe文件存放在哪儿。

找到目录C:\Windows\system32\dist\文件夹(可能也在C:\Windows\SysWOW64\dist\文件里,估计和Python 32bit/64bit有关),即可运行生成的exe文件

[options]

-F  生成一个exe单文件

-D  生成一个文件夹(默认选项)

posted @ 2016-10-16 00:24  Youth_Lee  阅读(4233)  评论(0编辑  收藏  举报