THE FREEZE SCRIPT=================(Directions for Windows are at the end of this file.)What is Freeze?---------------Freeze make it possible to ship arbitrary Python programs to peoplewho don't have Python. The shipped file (called a "frozen" version ofyour Python program) is an executable, so this only works if yourplatform is compatible with that on the receiving end (this is usuallya matter of having the same major operating system revision and CPUtype).The shipped file contains a Python interpreter and large portions ofthe Python run-time. Some measures have been taken to avoid linkingunneeded modules, but the resulting binary is usually not small.The Python source code of your program (and of the library moduleswritten in Python that it uses) is not included in the binary --instead, the compiled byte-code (the instruction stream usedinternally by the interpreter) is incorporated. This gives someprotection of your Python source code, though not much -- adisassembler for Python byte-code is available in the standard Pythonlibrary. At least someone running "strings" on your binary won't seethe source.How does Freeze know which modules to include?----------------------------------------------Previous versions of Freeze used a pretty simple-minded algorithm tofind the modules that your program uses, essentially searching forlines starting with the word "import". It was pretty easy to trick itinto making mistakes, either missing valid import statements, ormistaking string literals (e.g. doc strings) for import statements.This has been remedied: Freeze now uses the regular Python parser toparse the program (and all its modules) and scans the generated bytecode for IMPORT instructions. It may still be confused -- it will notknow about calls to the __import__ built-in function, or about importstatements constructed on the fly and executed using the 'exec'statement, and it will consider import statements even when they areunreachable (e.g. "if 0: import foobar").This new version of Freeze also knows about Python's new packageimport mechanism, and uses exactly the same rules to find importedmodules and packages. One exception: if you write 'from packageimport *', Python will look into the __all__ variable of the packageto determine which modules are to be imported, while Freeze will do adirectory listing.One tricky issue: Freeze assumes that the Python interpreter andenvironment you're using to run Freeze is the same one that would beused to run your program, which should also be the same whose sourcesand installed files you will learn about in the next section. Inparticular, your PYTHONPATH setting should be the same as for runningyour program locally. (Tip: if the program doesn't run when you type"python hello.py" there's little chance of getting the frozen versionto run.)How do I use Freeze?--------------------Normally, you should be able to use it as follows:python freeze.py hello.pywhere hello.py is your program and freeze.py is the main file ofFreeze (in actuality, you'll probably specify an absolute pathnamesuch as /usr/joe/python/Tools/freeze/freeze.py).What do I do next?------------------Freeze creates a number of files: frozen.c, config.c and Makefile,plus one file for each Python module that gets included namedM_<module>.c. To produce the frozen version of your program, you cansimply type "make". This should produce a binary file. If thefilename argument to Freeze was "hello.py", the binary will be called"hello".Note: you can use the -o option to freeze to specify an alternativedirectory where these files are created. This makes it easier toclean up after you've shipped the frozen binary. You should invoke"make" in the given directory.Freezing Tkinter programs-------------------------Unfortunately, it is currently not possible to freeze programs thatuse Tkinter without a Tcl/Tk installation. The best way to ship afrozen Tkinter program is to decide in advance where you are goingto place the Tcl and Tk library files in the distributed setup, andthen declare these directories in your frozen Python program usingthe TCL_LIBRARY, TK_LIBRARY and TIX_LIBRARY environment variables.For example, assume you will ship your frozen program in the directory<root>/bin/windows-x86 and will place your Tcl library filesin <root>/lib/tcl8.2 and your Tk library files in <root>/lib/tk8.2. Thenplacing the following lines in your frozen Python script before importingTkinter or Tix would set the environment correctly for Tcl/Tk/Tix:import osimport os.pathRootDir = os.path.dirname(os.path.dirname(os.getcwd()))import sysif sys.platform == "win32":sys.path = ['', '..\\..\\lib\\python-2.0']os.environ['TCL_LIBRARY'] = RootDir + '\\lib\\tcl8.2'os.environ['TK_LIBRARY'] = RootDir + '\\lib\\tk8.2'os.environ['TIX_LIBRARY'] = RootDir + '\\lib\\tix8.1'elif sys.platform == "linux2":sys.path = ['', '../../lib/python-2.0']os.environ['TCL_LIBRARY'] = RootDir + '/lib/tcl8.2'os.environ['TK_LIBRARY'] = RootDir + '/lib/tk8.2'os.environ['TIX_LIBRARY'] = RootDir + '/lib/tix8.1'elif sys.platform == "solaris":sys.path = ['', '../../lib/python-2.0']os.environ['TCL_LIBRARY'] = RootDir + '/lib/tcl8.2'os.environ['TK_LIBRARY'] = RootDir + '/lib/tk8.2'os.environ['TIX_LIBRARY'] = RootDir + '/lib/tix8.1'This also adds <root>/lib/python-2.0 to your Python pathfor any Python files such as _tkinter.pyd you may need.Note that the dynamic libraries (such as tcl82.dll tk82.dll python20.dllunder Windows, or libtcl8.2.so and libtcl8.2.so under Unix) are requiredat program load time, and are searched by the operating system loaderbefore Python can be started. Under Windows, the environmentvariable PATH is consulted, and under Unix, it may be theenvironment variable LD_LIBRARY_PATH and/or the systemshared library cache (ld.so). An additional preferred directory forfinding the dynamic libraries is built into the .dll or .so files atcompile time - see the LIB_RUNTIME_DIR variable in the Tcl makefile.The OS must find the dynamic libraries or your frozen program won't start.Usually I make sure that the .so or .dll files are in the same directoryas the executable, but this may not be foolproof.A workaround to installing your Tcl library files with your frozenexecutable would be possible, in which the Tcl/Tk library files areincorporated in a frozen Python module as string literals and writtento a temporary location when the program runs; this is currently leftas an exercise for the reader. An easier approach is to freeze theTcl/Tk/Tix code into the dynamic libraries using the Tcl ET code,or the Tix Stand-Alone-Module code. Of course, you can also simplyrequire that Tcl/Tk is required on the target installation, but becareful that the version corresponds.There are some caveats using frozen Tkinter applications:Under Windows if you use the -s windows option, writingto stdout or stderr is an error.The Tcl [info nameofexecutable] will be set to where theprogram was frozen, not where it is run from.The global variables argc and argv do not exist.A warning about shared library modules--------------------------------------When your Python installation uses shared library modules such as_tkinter.pyd, these will not be incorporated in the frozen program.Again, the frozen program will work when you test it, but it won'twork when you ship it to a site without a Python installation.Freeze prints a warning when this is the case at the end of thefreezing process:Warning: unknown modules remain: ...When this occurs, the best thing to do is usually to rebuild Pythonusing static linking only. Or use the approach described in the previoussection to declare a library path using sys.path, and place the modulessuch as _tkinter.pyd there.Troubleshooting---------------If you have trouble using Freeze for a large program, it's probablybest to start playing with a really simple program first (like the filehello.py). If you can't get that to work there's somethingfundamentally wrong -- perhaps you haven't installed Python. To do aproper install, you should do "make install" in the Python rootdirectory.Usage under Windows 95 or NT----------------------------Under Windows 95 or NT, you *must* use the -p option and point it tothe top of the Python source tree.WARNING: the resulting executable is not self-contained; it requiresthe Python DLL, currently PYTHON20.DLL (it does not require thestandard library of .py files though). It may also require one ormore extension modules loaded from .DLL or .PYD files; the modulenames are printed in the warning message about remaining unknownmodules.The driver script generates a Makefile that works with the Microsoftcommand line C compiler (CL). To compile, run "nmake"; this willbuild a target "hello.exe" if the source was "hello.py". Only thefiles frozenmain.c and frozen.c are used; no config.c is generated orused, since the standard DLL is used.In order for this to work, you must have built Python using the VC++(Developer Studio) 5.0 compiler. The provided project buildspython20.lib in the subdirectory pcbuild\Release of thje Python sourcetree, and this is where the generated Makefile expects it to be. Ifthis is not the case, you can edit the Makefile or (probably better)winmakemakefile.py (e.g., if you are using the 4.2 compiler, thepython20.lib file is generated in the subdirectory vc40 of the Pythonsource tree).It is possible to create frozen programs that don't have a consolewindow, by specifying the option '-s windows'. See the Usage below.Usage-----Here is a list of all of the options (taken from freeze.__doc__):usage: freeze [options...] script [module]...Options:-p prefix: This is the prefix used when you ran ``make install''in the Python build directory.(If you never ran this, freeze won't work.)The default is whatever sys.prefix evaluates to.It can also be the top directory of the Python sourcetree; then -P must point to the build tree.-P exec_prefix: Like -p but this is the 'exec_prefix', used toinstall objects etc. The default is whatever sys.exec_prefixevaluates to, or the -p argument if given.If -p points to the Python source tree, -P must pointto the build tree, if different.-e extension: A directory containing additional .o files thatmay be used to resolve modules. This directoryshould also have a Setup file describing the .o files.On Windows, the name of a .INI file describing oneor more extensions is passed.More than one -e option may be given.-o dir: Directory where the output files are created; default '.'.-m: Additional arguments are module names instead of filenames.-a package=dir: Additional directories to be added to the package's__path__. Used to simulate directories added by thepackage at runtime (eg, by OpenGL and win32com).More than one -a option may be given for each package.-l file: Pass the file to the linker (windows only)-d: Debugging mode for the module finder.-q: Make the module finder totally quiet.-h: Print this help message.-x module Exclude the specified module.-i filename: Include a file with additional command line options. Usedto prevent command lines growing beyond the capabilities ofthe shell/OS. All arguments specified in filenameare read and the -i option replaced with the parsedparams (note - quoting args in this file is NOT supported)-s subsystem: Specify the subsystem (For Windows only.);'console' (default), 'windows', 'service' or 'com_dll'-w: Toggle Windows (NT or 95) behavior.(For debugging only -- on a win32 platform, win32 behavioris automatic.)Arguments:script: The Python script to be executed by the resulting binary.module ...: Additional Python modules (referenced by pathname)that will be included in the resulting binary. Thesemay be .py or .pyc files. If -m is specified, these aremodule names that are search in the path instead.--Guido van Rossum (home page: http://www.python.org/~guido/)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。