The examples in this article describe how Python packages executables. Share to everyone for your reference, specific as follows:
Python programs need to rely on a native-installed Python library, if you want to run on a machine that does not have Python installed, you need to package the distribution, there are currently two more useful tools: Pyinstaller and Py2exe. Where Py2exe is applied under Windows, and Pyinstall can be applied to Windows, Linux, and Mac OS X.
Here is only a piece of Py2exe packaged instance code. (Py2exe download address)
#coding =utf-8
from distutils.core Import setup
import py2exe
includes = ["Encodings", "encodings.*"]
#要包含的其它库文件
options = {"Py2exe":
{"
Compressed": 1, #压缩
"optimize": 2,
"ASCII": 1,
"includes ": Includes,
" Bundle_files ": 1 #所有文件打包成一个exe文件
}
}
Setup (
options = options,
zipfile= None, #不生成library. zip file
console=[{"script": "main.py", "Icon_resources": [(1, "Q.ico")]}] #源文件, program icon
)
If the above source code is saved as mysetup.py, the Package command is: Python mysetup.py py2exe.
PS: The Use of Enigma Virtual box can also make Py2exe packaging out of the single file More perfect. Enigma Virtual Box can click here to download: http://www.jb51.net/softs/425055.html
Two used instances:
(1), background operation
#coding =utf-8
from distutils.core Import setup
import py2exe
includes = ["Encodings", "encodings.*"]
#要包含的其它库文件
options = {"Py2exe":
{"
Compressed": 1, #压缩
"optimize": 2,
"ASCII": 1,
"includes ": Includes,
" Bundle_files ": 1 #所有文件打包成一个exe文件
}
}
Setup (
options = options,
zipfile= None, #不生成library. zip file
windows=[{"script": "main.py"}] #源文件
)
(2), have to have a console window, and can not be packaged as an EXE file. (Walker is because of the call to the browser)
#coding =utf-8 from
distutils.core Import setup
import py2exe
setup (
console = [{' Script ':] Main.py "}],
options={
" Py2exe ": {
" skip_archive ": True,
" unbuffered ": true,
" optimize ": 2
}
}
)
PS: About using Pyinstalle to pack python scripts into exe files, refer to this site article: http://www.jb51.net/article/88235.htm
More information about Python-related content can be viewed in this site: "Python file and directory operation tips Summary", "Python text file Operation tips Summary", "Python URL operation tips Summary", "Python Picture Operation tips Summary", " Python data structure and algorithm tutorial, Python socket Programming Tips Summary, Python function Usage tips Summary, python string manipulation tips and Python introductory and advanced classic tutorials
I hope this article will help you with Python programming.