Transferred fromHttp://www.cnblogs.com/balian/archive/2012/11/22/2782308.html
Recently, python was used to develop a test tool for the project. Because the user is in another department, the leader wants to release the Python script to be executable without running the python platform.ProgramIt is best to use a single EXE file and protect the source code of our department. Pyinstaller meets this requirement. Currently, the latest version of pyinstaller is 2.0, which supports python2.7. Next, this article will discuss how to use pyinstaller2 to convert a Python script file to a Windows Executable EXE file. All the tools mentioned in this article can be downloaded. This blog post is original from Balian. You are welcome to repost it. For more information, see the original author.
To install pyinstaller2, see:
Use pyinstaller2 to convert the Python script to an executable file (above-the installation part)
Http://www.cnblogs.com/balian/archive/2012/11/21/2780503.html
Main. py is a simple Python script in the C-drive root directory folder scripts.
'''Main. py '''Print'Main. py-Hello world! '
To convert main. py to a single EXE file, run the following command in the pyintstller2 installation folder:
Python pyinstaller. py-f c: \ scripts \ main. py
The specific execution result of this command is as follows.
This article is from Balian. You can find a single main.exe file in the C: \ pyinstaller2 \ main \ Dist folder ,. Now main.exe can be used for publishing.
In the command, parameter-F indicates that a single EXE file is generated. If you do not have this parameter, You need to publish a folder, for example.
How does pyinstaller2 support Python internal modules? Use the same commandCodePackaging, no problem.
'''Main. py '''Import TimePrint'Main. py-Hello world! 'Time. Sleep (10)
Next, let's take a look at how pyinstaller2 handles user-defined modules. The file test_module.py and Main. py are included in the scripts folder in the C drive root directory. They are as follows:
'''Test _ module. py '''DefTest_print ():Print'Test _ module. py-ImportModuleSuccessfully .! \ N'
And
'''Main. py '''Import TimeImportTest_modulePrint'Main. py-Hello world! 'Time. Sleep (5) test_module.test_print ()Time. Sleep (5)
If you still use the same command to package it into a single EXE file, pyinstaller2 indicates no pressure.