把Python打包成可执行文件

  要想在没有安装Python集成环境的电脑上运行开发的Python程序,必须把Python文件打包成.exe格式的可执行文件(针对于windows)。网上介绍的各种打包工具的对比如下:

Solution Windows Linux OS X Python 3 License One-file mode Zipfile import Eggs pkg_resources support
bbFreeze yes yes yes no MIT no yes yes yes
py2exe yes no no yes MIT yes yes no no
pyInstaller yes yes yes no GPL yes no yes no
cx_Freeze yes yes yes yes PSF no yes yes no
py2app no no yes yes MIT no yes yes yes

 

1、安装PyInstaller  

pip install pyinstaller

 

2、PyInstaller的使用方法

Python的打包工作PyInstaller提供了两种把.py文件包成.exe文件的方式:

第一种方式是把由.py文件打包而成的.exe文件及相关文件放在一个目录中。这种方式是默认方式,称为 onedir 方式。语法为:

pyinstaller 应用程序

例如:

pyinstaller Hello.py

    

第二种方式是加上 -F 参数后把制作出的.exe打包成一个独立的.exe格式的可执行文件,称为 onefile 方式。语法为:

pyinstaller -F 应用程序

例如:

pyinstaller -F Hello.py 

猜你喜欢

转载自www.cnblogs.com/Phantom3389/p/9146970.html