PyInstaller Manual.docx

上传人:b****6 文档编号:8861168 上传时间:2023-02-02 格式:DOCX 页数:35 大小:50.45KB
下载 相关 举报
PyInstaller Manual.docx_第1页
第1页 / 共35页
PyInstaller Manual.docx_第2页
第2页 / 共35页
PyInstaller Manual.docx_第3页
第3页 / 共35页
PyInstaller Manual.docx_第4页
第4页 / 共35页
PyInstaller Manual.docx_第5页
第5页 / 共35页
点击查看更多>>
下载资源
资源描述

PyInstaller Manual.docx

《PyInstaller Manual.docx》由会员分享,可在线阅读,更多相关《PyInstaller Manual.docx(35页珍藏版)》请在冰豆网上搜索。

PyInstaller Manual.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 农学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1