Use pyinstaller2 to convert the Python script to an executable file (in-use part)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.