使用Pyinstaller打包exe文件詳細(xì)圖文教程_第1頁(yè)
使用Pyinstaller打包exe文件詳細(xì)圖文教程_第2頁(yè)
使用Pyinstaller打包exe文件詳細(xì)圖文教程_第3頁(yè)
使用Pyinstaller打包exe文件詳細(xì)圖文教程_第4頁(yè)
使用Pyinstaller打包exe文件詳細(xì)圖文教程_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第使用Pyinstaller打包exe文件詳細(xì)圖文教程目錄前言場(chǎng)景說(shuō)明pyinstaller安裝打包參數(shù)打包問(wèn)題解決方法匯總總結(jié)

前言

在業(yè)務(wù)場(chǎng)景中,經(jīng)常需要Python開(kāi)發(fā)一些小程序/腳本/GUI界面,交付給一些小白或未安裝Python的小伙伴們使用。

噔噔蹬蹬

pyinstaller閃亮登場(chǎng)

場(chǎng)景說(shuō)明

使用Pyinstaller將Python腳本或者項(xiàng)目打包,生成可執(zhí)行的.exe文件。Pyinstaller是一個(gè)很不錯(cuò)的免費(fèi)打包工具,支持Windows,Linux和MacOS,完美支持32位和64位系統(tǒng)。除了Pyinstaller,還可以使用py2exe進(jìn)行打包

pyinstaller安裝

pipinstallpyinstaller

打包參數(shù)

#常用打包參數(shù)

#-F-D互斥參數(shù)

-F打包成一個(gè)exe文件,小項(xiàng)目可以采用,打開(kāi)比較慢,多個(gè).py打包時(shí)不能使用

-D默認(rèn)參數(shù),打包結(jié)果放入到創(chuàng)建的文件夾中,可以看到里面有很多的依賴(lài)文件

#-w-c互斥參數(shù)

-w使用項(xiàng)目的GUI界面,無(wú)cmd控制臺(tái)

-c默認(rèn)參數(shù),使用cmd控制臺(tái)如果打包文件執(zhí)行報(bào)錯(cuò),可嘗試用-c顯示控制臺(tái)

-n執(zhí)行項(xiàng)目的名稱(chēng),默認(rèn).py的文件名

-i將ico圖標(biāo)打包到exe文件中

--hidden-import打包時(shí)導(dǎo)包信息

#打包PyQt項(xiàng)目強(qiáng)烈建議帶上以下參數(shù)

--hidden-importPyQt5.sip

#打包命令示例

#在項(xiàng)目的根目錄下執(zhí)行打包命令

pyinstaller-wxxx.py--hidden-importPyQt5.sip

#打包結(jié)果輸出在項(xiàng)目根目錄下的dist文件夾中

#不建議使用-F打包成一個(gè)exe文件所謂:打包一時(shí)爽,打開(kāi)5秒鐘

#非-F命令下,靜態(tài)資源、建好的Sqlite數(shù)據(jù)庫(kù)可以直接放入dist中生成的文件夾中

Pyinstaller只是將Python解釋器和腳本打包成一個(gè)可執(zhí)行文件,不同于編譯成真正的機(jī)器碼。所以代碼的運(yùn)行效率是降低的,只是解決了小白用戶的操作難度。打包時(shí)會(huì)分析項(xiàng)目的依賴(lài),并將相關(guān)的依賴(lài)打包進(jìn)來(lái),并進(jìn)行加密處理不同的操作系統(tǒng),需要在不同的操作系統(tǒng)進(jìn)行打包。

打包問(wèn)題解決方法匯總

debug

控制臺(tái)debug

在本地運(yùn)行成功,建議在第一次打包exe時(shí)使用-c命令,這樣可以在控制臺(tái)中顯示可能的報(bào)錯(cuò)信息。

如果打包時(shí)沒(méi)有用-c不會(huì)出現(xiàn)控制臺(tái)或者控制臺(tái)一閃而過(guò),看不到報(bào)錯(cuò)信息,可以在cmd命令行窗口執(zhí)行exe文件fatalerrorfaildtoexecutescriptfile

Pyinstaller打包時(shí)有些庫(kù)沒(méi)有打包進(jìn)去,可以將報(bào)錯(cuò)信息中的庫(kù)通過(guò)--hidden-import報(bào)錯(cuò)的包的進(jìn)行打包

pyinstaller打包python3.6+PyQt5中各種錯(cuò)誤的解決方案

依賴(lài)報(bào)錯(cuò)打包結(jié)果文件過(guò)大

幫助中的參數(shù)

pyinstaller-h

usage:pyinstaller[-h][-v][-D][-F][--specpathDIR][-nNAME]

[--add-dataDESTorSRC:DEST]

[--add-binaryDESTorSRC:DEST][-pDIR]

[--hidden-importMODULENAME]

[--additional-hooks-dirHOOKSPATH]

[--runtime-hookRUNTIME_HOOKS][--exclude-moduleEXCLUDES]

[--keyKEY][-d{all,imports,bootloader,noarchive}][-s]

[--noupx][--upx-excludeFILE][-c][-w]

[-iFILE.icoorFILE.exe,IDorFILE.icns]

[--version-fileFILE][-mFILEorXML][-rRESOURCE]

[--uac-admin][--uac-uiaccess][--win-private-assemblies]

[--win-no-prefer-redirects]

[--osx-bundle-identifierBUNDLE_IDENTIFIER]

[--runtime-tmpdirPATH][--bootloader-ignore-signals]

[--distpathDIR][--workpathWORKPATH][-y]

[--upx-dirUPX_DIR][-a][--clean][--log-levelLEVEL]

scriptname[scriptname...]

positionalarguments:

scriptnamenameofscriptfilestobeprocessedorexactlyone

.spec-file.Ifa.spec-fileisspecified,mostoptions

areunnecessaryandareignored.

optionalarguments:

-h,--helpshowthishelpmessageandexit

-v,--versionShowprogramversioninfoandexit.

--distpathDIRWheretoputthebundledapp(default:.\dist)

--workpathWORKPATHWheretoputallthetemporaryworkfiles,.log,.pyz

andetc.(default:.\build)

-y,--noconfirmReplaceoutputdirectory(default:

SPECPATH\dist\SPECNAME)withoutaskingfor

confirmation

--upx-dirUPX_DIRPathtoUPXutility(default:searchtheexecution

path)

-a,--asciiDonotincludeunicodeencodingsupport(default:

includedifavailable)

--cleanCleanPyInstallercacheandremovetemporaryfiles

beforebuilding.

--log-levelLEVELAmountofdetailinbuild-timeconsolemessages.LEVEL

maybeoneofTRACE,DEBUG,INFO,WARN,ERROR,

CRITICAL(default:INFO).

Whattogenerate:

-D,--onedirCreateaone-folderbundlecontaininganexecutable

(default)

-F,--onefileCreateaone-filebundledexecutable.

--specpathDIRFoldertostorethegeneratedspecfile(default:

currentdirectory)

-nNAME,--nameNAMENametoassigntothebundledappandspecfile

(default:firstscript'sbasename)

Whattobundle,wheretosearch:

--add-dataDESTorSRC:DEST

Additionalnon-binaryfilesorfolderstobeaddedto

theexecutable.Thepathseparatorisplatform

specific,``os.pathsep``(whichis``;``onWindows

and``:``onmostunixsystems)isused.Thisoption

canbeusedmultipletimes.

--add-binaryDESTorSRC:DEST

Additionalbinaryfilestobeaddedtotheexecutable.

Seethe``--add-data``optionformoredetails.This

optioncanbeusedmultipletimes.

-pDIR,--pathsDIRApathtosearchforimports(likeusingPYTHONPATH).

Multiplepathsareallowed,separatedby';',oruse

thisoptionmultipletimes

--hidden-importMODULENAME,--hiddenimportMODULENAME

Nameanimportnotvisibleinthecodeofthe

script(s).Thisoptioncanbeusedmultipletimes.

--additional-hooks-dirHOOKSPATH

Anadditionalpathtosearchforhooks.Thisoption

canbeusedmultipletimes.

--runtime-hookRUNTIME_HOOKS

Pathtoacustomruntimehookfile.Aruntimehookis

codethatisbundledwiththeexecutableandis

executedbeforeanyothercodeormoduletosetup

specialfeaturesoftheruntimeenvironment.This

optioncanbeusedmultipletimes.

--exclude-moduleEXCLUDES

Optionalmoduleorpackage(thePythonname,notthe

pathname)thatwillbeignored(asthoughitwasnot

found).Thisoptioncanbeusedmultipletimes.

--keyKEYThekeyusedtoencryptPythonbytecode.

Howtogenerate:

-d{all,imports,bootloader,noarchive},--debug{all,imports,bootloader,noarchive}

Provideassistancewithdebuggingafrozen

application.Thisargumentmaybeprovidedmultiple

timestoselectseveralofthefollowingoptions.

-all:Allthreeofthefollowingoptions.

-imports:specifythe-voptiontotheunderlying

Pythoninterpreter,causingittoprintamessage

eachtimeamoduleisinitialized,showingthe

place(filenameorbuilt-inmodule)fromwhichit

isloaded.See

/3/using/cmdline.html#id4.

-bootloader:tellthebootloadertoissueprogress

messageswhileinitializingandstartingthe

bundledapp.Usedtodiagnoseproblemswith

missingimports.

-noarchive:insteadofstoringallfrozenPython

sourcefilesasanarchiveinsidetheresulting

executable,storethemasfilesintheresulting

outputdirectory.

-s,--stripApplyasymbol-tablestriptotheexecutableand

sharedlibs(notrecommendedforWindows)

--noupxDonotuseUPXevenifitisavailable(works

differentlybetweenWindowsand*nix)

--upx-excludeFILEPreventabinaryfrombeingcompressedwhenusingupx.

Thisistypicallyusedifupxcorruptscertain

binariesduringcompression.FILEisthefilenameof

thebinarywithoutpath.Thisoptioncanbeused

multipletimes.

WindowsandMacOSXspecificoptions:

-c,--console,--nowindowed

Openaconsolewindowforstandardi/o(default).On

Windowsthisoptionwillhavenoeffectifthefirst

scriptisa'.pyw'file.

-w,--windowed,--noconsole

WindowsandMacOSX:donotprovideaconsolewindow

forstandardi/o.OnMacOSXthisalsotriggers

buildinganOSX.appbundle.OnWindowsthisoption

willbesetifthefirstscriptisa'.pyw'file.This

optionisignoredin*NIXsystems.

-iFILE.icoorFILE.exe,IDorFILE.icns,--iconFILE.icoorFILE.exe,IDorFILE.icns

FILE.ico:applythaticontoaWindowsexecutable.

FILE.exe,ID,extracttheiconwithIDfromanexe.

FILE.icns:applytheicontothe.appbundleonMacOS

Windowsspecificoptions:

--version-fileFILEaddaversionresourcefromFILEtotheexe

-mFILEorXML,--manifestFILEorXML

addmanifestFILEorXMLtotheexe

-rRESOURCE,--resourceRESOURCE

AddorupdatearesourcetoaWindowsexecutable.The

RESOURCEisonetofouritems,

FILE[,TYPE[,NAME[,LANGUAGE]]].FILEcanbeadatafile

oranexe/dll.Fordatafiles,atleastTYPEandNAME

mustbespecified.LANGUAGEdefaultsto0ormaybe

specifiedaswildcard*toupdateallresourcesofthe

givenTYPEandNAME.Forexe/dllfiles,allresources

fromFILEwillbeadded/updatedtothefinal

executableifTYPE,NAMEandLANGUAGEareomittedor

specifiedaswildcard*.Thisoptioncanbeused

multipletimes.

--uac-adminUsingthisoptioncreatesaManifestwhichwill

requestelevationuponapplicationrestart.

--uac-uiaccessUsingthisoptionallowsanelevatedapplicationto

workwithRemoteDesktop.

WindowsSide-by-sideAssemblysearchingoptions(advanced):

--win-private-assemblies

AnySharedAssembliesbundledintotheapplication

willbechangedintoPrivateAssemblies.Thismeans

theexactversionsoftheseassemblieswillalwaysbe

used,andanynewerversionsinstalledonuser

machinesatthesystemlevelwillbeignored.

--win-no-prefer-redirects

WhilesearchingforSharedorPrivateAssembliesto

bundleintotheapplication,PyInstallerwillprefer

nottofollowpoliciesthatredirecttonewer

versions,andwilltrytobundletheexactversionsof

theassembly.

MacOSXspecific

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論