PyInstaller Manual.docx
- 文档编号:8861168
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:35
- 大小:50.45KB
PyInstaller Manual.docx
《PyInstaller Manual.docx》由会员分享,可在线阅读,更多相关《PyInstaller Manual.docx(35页珍藏版)》请在冰豆网上搜索。
PyInstallerManual
PyInstallerManual
Version:
PyInstallerv1.5.1
Homepage:
http:
//www.pyinstaller.org
Author:
GiovanniBajo&WilliamCaban(basedonGordonMcMillan'smanual)
Contact:
rasky@
Revision:
1545
SourceURL:
$HeadURL:
$
Copyright:
Thisdocumenthasbeenplacedinthepublicdomain.
Contents
∙Requirements
oWindows
oLinux
oMacOSX
∙GettingStarted
oInstallingPyInstaller
oConfiguringyourPyInstallersetup
oCreateaspecfileforyourproject
oBuildyourproject
oWindowsCOMServersupport
oBuildingOptimized
oANoteonusingUPX
oHowone-filemodeworks
o.eggfilesandsetuptools
∙PyInstallerUtilities
oArchiveViewer
obindepend
oGrabVersion(Windows)
oAnalyzingDependencies
opyinstaller.py
∙SpecFiles
oIntroduction
oTOCClass(TableofContents)
oTargetSubclasses
▪Analysis
▪PYZ
▪PKG
▪EXE
▪DLL
▪COLLECT
▪Tree
∙WhenThingsGoWrong
oFindingoutWhatWentWrong
▪BuildtimeWarnings
▪GettingDebugMessages
▪GettingPython'sVerboseImports
oHelpingPyInstallerFindModules
▪ExtendingthePath
▪ListingHiddenImports
▪ExtendingaPackage's__path__
▪ChangingRuntimeBehavior
▪Adaptingtobeing"frozen"
▪AccessingDataFiles
∙Miscellaneous
oWin9xpopen
oSelf-extractingexecutables
▪OnePassExecution
▪TwoPassExecution
∙PyInstallerArchives
oArchivesIntroduction
oZlibArchive
oCArchive
∙License
∙Appendix
oBuildingthebootloaders
▪Developmenttools
▪Building
▪LinuxStandardBase(LSB)binary
omf.py:
AModulefinderReplacement
▪ImportTracker
▪analyze_one()
▪ModuleClasses
▪codescanning
▪Hooks
▪Warnings
▪CrossReference
▪mfUsage
oiu.py:
AnimputilReplacement
▪ImportManager
▪ImportDirector
▪PathImportDirector
▪Owner
▪Packages
▪Possibilities
▪Compatibility
▪Performance
▪Limitations
▪iuUsage
Requirements
Windows
PyWin32
PythonextensionsforWindowsisonlynecessaryforusersofPython2.6+.
BacktoTop
Linux
ldd
Consoleapplicationtoprintthesharedlibrariesrequiredbyeachprogramorsharedlibrary.
objdump
Consoleapplicationtodisplayinformationfromobjectfiles.
BacktoTop
MacOSX
Xcode
isasuiteoftoolsfordevelopingsoftwareforMacOSX.ItcanbealsoinstalledfromyourMacOSXInstallDVD.Itisnotnecessarytoinstalltheversion4ofXcode.PyInstallerdependsonotoolwhichisinstalledtogetherwithXcode.otooldisplaysinformationofobjectfilesorlibraries.
BacktoTop
GettingStarted
InstallingPyInstaller
First,unpackthearchiveonyourpathofchoice.InstallerisnotaPythonpackage,soitdoesn'tneedtogoinsite-packages,orhavea.pthfile.Forthepurposeofthisdocumentationwewillassume/your/path/to/pyinstaller/.Youwillbeusingacoupleofscriptsinthe/your/path/to/pyinstaller/directory,andthesewillfindeverythingtheyneedfromtheirownlocation.Forconvenience,keepthepathstothesescriptsshort(don'tinstallinadeeplynestedsubdirectory).
BacktoTop
ConfiguringyourPyInstallersetup
Inthe/your/path/to/pyinstaller/directory,run:
pythonConfigure.py
ThiswillconfigurePyInstallerusagebasedonthecurrentsystem,andsavesomeinformationintoconfig.datthatwouldotherwiseberecomputedeverytime.
Itcanbererunatanytimeifyourconfigurationchanges.Itmustberunatleastoncebeforetryingtobuildanything.
PyInstallerisdependanttotheversionofpythonyouconfigureitfor.Inotherwords,youwillneedaseparatecopyofPyInstallerforeachPythonversionyouwishtoworkwithoryou'llneedtorerunConfigure.pyeverytimeyouswitchthePythonversion).
BacktoTop
Createaspecfileforyourproject
[ForWindowsCOMserversupport,seesectionWindowsCOMServerSupport]
Thisisthefirststeptodo.ThespecfileisthedescriptionofwhatyouwantPyInstallertodowithyourprogram.IntherootdirectoryofPyInstaller,thereisasimplewizardtocreatesimplespecfilesthatcoverallbasicusages:
pythonMakespec.py[--onefile]yourprogram.py
Bydeafult,Makespec.pygeneratesaspecfilethattellsPyInstallertocreateadistributiondirectorycontainsthemainexecutableandthedynamiclibraries.Theoption--onefilespecifiesthatyouwantPyInstallertobuildasinglefilewitheverythinginside.
ElaboratingonMakespec.py,thisisthesupportedcommandline:
pythonMakespec.py[opts]
WhereallowedOPTIONSare:
-F,--onefile
produceasinglefiledeployment(seebelow).
-D,--onedir
produceasingledirectorydeployment(default).
-K,--tk
includeTCL/TKinthedeployment.
-a,--ascii
donotincludeencodings.Thedefault(onPythonversionswithunicodesupport)isnowtoincludeallencodings.
-d,--debug
usedebug(verbose)versionsoftheexecutables.
-w,--windowed,--noconsole
UsetheWindowssubsystemexecutable,whichdoesnotopentheconsolewhentheprogramislaunched.(Windowsonly)
-c,--nowindowed,--console
Usetheconsolesubsystemexecutable.Thisisthedefault.(Windowsonly)
-s,--strip
theexecutableandallsharedlibrarieswillberunthroughstrip.Notethatcygwin'sstriptendstorendernormalWin32dllsunusable.
-X,--upx
ifyouhaveUPXinstalled(detectedbyConfigure),thiswilluseittocompressyourexecutable(and,onWindows,yourdlls).Seenotebelow.
-oDIR,--out=DIR
createthespecfileindirectory.Ifnotspecified,andthecurrentdirectoryisInstaller'srootdirectory,anoutputsubdirectorywillbecreated.Otherwisethecurrentdirectoryisused.
-pDIR,--paths=DIR
setbasepathforimport(likeusingPYTHONPATH).Multipledirectoriesareallowed,separatingthemwiththepathseparator(';'underWindows,':
'underLinux),orusingthisoptionmultipletimes.
--icon=
addfile.icototheexecutable'sresources.(Windowsonly)
--icon=
addthen-thinconinfile.exetotheexecutable'sresources.(Windowsonly)
-vFILE,--version=FILE
addverfileasaversionresourcetotheexecutable.(Windowsonly)
-nNAME,--name=NAME
optionalnametoassigntotheproject(fromwhichthespecfilenameisgenerated).Ifomitted,thebasenameofthe(first)scriptisused.
[Forbuildingwithoptimizationon(likePython-O),seesectionBuildingOptimized]
Forsimpleprojects,thegeneratedspecfilewillprobablybesufficient.Formorecomplexprojects,itshouldberegardedasatemplate.ThespecfileisactuallyPythoncode,andmodifyingitshouldbeease.SeeSpecFilesfordetails.
BacktoTop
Buildyourproject
pythonBuild.pyspecfile
Abuildprojectsubdirectorywillbecreatedinthespecfile'sdirectory.ThisisaprivateworkspacesothatBuild.pycanactlikeamakefile.Anynamedtargetswillappearinthespecfile'sdirectory.
Thegeneratedfileswillbeplacedwithinthedistsubdirectory;that'swherethefilesyouareinterestedinwillbeplaced.
Inmostcases,thiswillbeallyouhavetodo.Ifnot,seeWhenthingsgowrongandbesuretoreadtheintroductiontoSpecFiles.
BacktoTop
WindowsCOMServersupport
ForWindowsCOMsupportexecute:
pythonMakeCOMServer.py[OPTION]script...
Thiswillgenerateanewscriptdrivescript.pyandaspecfileforthescript.
Theseoptionsareallowed:
--debug
Usetheverboseversionoftheexecutable.
--verbose
RegistertheCOMserver(s)withthequietflagoff.
--ascii
donotincludeencodings(thisispassedthroughtoMakespec).
--out
Generatethedriverscriptandspecfileindir.
NowBuildyourprojectonthegeneratedspecfile.
Ifyouhavethewin32dbgpackageinstalled,youcanuseitwiththegeneratedCOMserver.Inthedriverscript,setdebug=1intheregistrationline.
Warnings:
theinprocessCOMserversupportwillnotworkwhentheclientprocessalreadyhasPythonloaded.Itwouldberathertrickytonon-obtrusivelyhookintoanalreadyrunningPython,buttheshow-stopperisthatthePython/CAPIwon'tletusfindoutwhichinterpreterinstanceIshouldhookinto.(Ifthisisimportanttoyou,youmightexperimentwithusingapartmentthreading,whichseemsthebestpossibilitytogetthistowork).Tousea"frozen"COMserverfromaPythonprocess,you'llhavetoloaditasanexe:
o=win32com.client.Dispatch(progid,
clsctx=pythoncom.CLSCTX_LOCAL_SERVER)
MakeCOMServeralsoassumesthatyourtoplevelcode(registrationetc.)is"normal".Ifit'snot,youwillhavetoeditthegeneratedscript.
BacktoTop
BuildingOptimized
Therearetwofacetstorunningoptimized:
gathering.pyo's,andsettingthePy_OptimizeFlag.Installerwillgather.pyo'sifitisrunoptimized:
python-OBuild.py...
ThePy_OptimizeFlagwillbesetifyouusea('O','','OPTION')inoneoftheTOCsbuildingtheEXE:
exe=EXE(pyz,
a.scripts+[('O','','OPTION')],
...
SeeSpecFilesfordetails.
BacktoTop
ANoteonusingUPX
OnbothWindowsandLinux,UPXcangivetrulystartlingcompression-thedaysoffittingsomethingusefulonadiskettearenotgoneforever!
InstallerhasbeentestedwithmanyUPXversionswithoutproblems.JustgetitandinstallitonyourPATH,thenrerunconfigure.
ForWindows,thereisaproblemofcompatibilitybetweenUPXandexecutablesgeneratedbyMicrosoftVisualStudio.NET2003(ortheequivalentfreetoolkitavailablefordownload).ThisisespeciallyworrisomeforusersofPython2.4+,wheremostextensions(andPythonitself)arecompiledwiththatcompiler.ThisissuehasbeenfixedinlaterbetaversionsofUPX,soyouwillneedatleastUPX1.92beta.Configure.pywillcheckthisforyouandcomplainifyouhavean
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PyInstaller Manual
![提示](https://static.bdocx.com/images/bang_tan.gif)