python3 安装pyinstaller_python3.7 打包(.exe)神器——pyinstaller 安装及用法
python打包工具都有哪些?主要有:py2exe、pyinstaller、cx_Freeze、nuitka等
工具名稱
windows
linux
是否支持單文件模式
bbfreeze
yes
yes
no
py2exe
yes
no
yes
pyinstaller
yes
yes
yes
cx_Freeze
yes
yes
no
py2app
no
no
yes
nuitka
yes
yes
yes
(上表來源于網絡,未經考證)
本文介紹功能比較強大的pyinstaller
Github介紹:https://github.com/pyinstaller/pyinstaller
使用手冊:https://pyinstaller.readthedocs.io/en/latest/#
一、 pyinstaller 介紹
以下摘取官網介紹(能力有限,英文可能翻譯的不準確):
PyInstaller reads a Python script written by you. It analyzes your code to discover every other module and library your script needs in order to execute. Then it collects copies of all those files -- including the active Python interpreter! -- and puts them with your script in a single folder, or optionally in a single executable file.
PyInstaller is tested against Windows, Mac OS X, and GNU/Linux. However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows; to make a GNU/Linux app you run it in GNU/Linux, etc. PyInstaller has been used successfully with AIX, Solaris, FreeBSD and OpenBSD, but is not tested against them as part of the continuous integration tests.
python程序的打包工具
支持Windows, Mac OS X, and GNU/Linux,但是不保證支持?AIX, Solaris, FreeBSD and OpenBSD
不能交叉編譯,例如在win平臺上打包的文件不能移植在Linux上運行
Main Advantages
Works out-of-the-box with any Python version 3.5-3.8.
Fully multi-platform, and uses the OS support to load the dynamic libraries, thus ensuring full compatibility.
Correctly bundles the major Python packages such as numpy, PyQt4, PyQt5, PySide, Django, wxPython, matplotlib and others out-of-the-box.
Compatible with many 3rd-party packages out-of-the-box. (All the required tricks to make external packages work are already integrated.)
Libraries like PyQt5, PyQt4, PySide, wxPython, matplotlib or Django are fully supported, without having to handle plugins or external data files manually.
Works with code signing on OS X.
Bundles MS Visual C++ DLLs on Windows.
主要優勢:
開箱即用(雙擊exe文件即可運行),支持任何python3.5-3.8任何版本
支持多平臺,利用操作系統下載動態庫以保證兼容性
已經綁定了一些常用的安裝包,如numpy, PyQt4, PyQt5, PySide, Django, wxPython, matplotlib等,并且兼容很多第三方安裝包
Requirements and Tested Platforms
Python:
3.5-3.8
tinyaes?1.0+ (only if using bytecode encryption). Instead of installing tinyaes,?pip install pyinstaller[encryption]?instead.
Windows (32bit/64bit):
PyInstaller should work on Windows 7 or newer, but we only officially support Windows 8+.
We don't support Python installed from the Windows store when not using virtual environments due to?permission errors?that can't easily be fixed.
GNU/Linux (32bit/64bit)
ldd: Console application to print the shared libraries required by each program or shared library. This typically can be found in the distribution-package glibc or libc-bin.
objdump: Console application to display information from object files. This typically can be found in the distribution-package binutils.
objcopy: Console application to copy and translate object files. This typically can be found in the distribution-package binutils, too.
Mac OS X (64bit):
Mac OS X 10.7 (Lion) or newer.
支持的python版本:3.5-3.8
支持的操作系統:win7 及以上 32bit/64bit、GNU/Linux (32bit/64bit)、Mac OS X 10.7 (Lion) 及以上
二、?pyinstaller 安裝
pip install pyinstaller
三、pyinstaller 用法
假如我們要打包一個demo.py文件,基本過程是:打開cmd,并切換到demo.py文件所在的目錄,注意路徑中不要有中文
執行命令:pyinstaller demo.py
在當前的目錄下,將會生成兩個文件夾:build和dist。
dist里面就是所有可執行文件,點擊demo.exe就能運行了。
pyinstaller指令的常見可選參數:
可選參數格式舉例功能說明
-F
pyinstaller -F demo.py
只在dist中生產一個demo.exe文件。
-D
pyinstaller -D demo.py
默認選項,除了demo.exe外,還會在在dist中生成很多依賴文件,推薦使用。
-c
pyinstaller -c demo.py
默認選項,只對windows有效,使用控制臺,就像編譯運行C程序后的黑色彈窗。
-w
pyinstaller -w demo.py
只對windows有效,不使用控制臺。
-p
pyinstaller -p E:\python\Lib\site-packages demo.py
設置導入路徑,一般用不到。
-i
pyinstaller -i D:\file.icon demo.py
將file.icon設置為exe文件的圖標,推薦一個icon網站:icon
上面的可選參數可以組合使用,比如pyinstaller -F -i D:\file.icon demo.py。
能夠from xxx import yyy就盡量不要import xxx,這樣可以減少打包后的體積。
ps:我在安裝時遇到找不到PyQt5.sip模塊的問題
四、pyinstaller 耗時
我寫了個小腳本打包后快200M了,而且非常慢……和C編譯的速度差了幾百萬個數量級吧……也就是做做小程序用,大型的真心還是別折騰了
總結
以上是生活随笔為你收集整理的python3 安装pyinstaller_python3.7 打包(.exe)神器——pyinstaller 安装及用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sql的加减乘除运算_实现四则运算的一条
- 下一篇: 三禧科技 工业机器人_redmi not