Pyinstaller package Python script as EXE executable program

Source: Internet
Author: User
Tags python script

I. Description of Pyinstaller

Pyinstaller is a third-party module, hosted on GitHub, which is a Python script and its dependent modules packaged into a standalone executable program that can run on machines that do not have a Python environment installed. Linux/unix/mac and windows are supported, but it is important to note that packaging on any platform will generate standalone programs that can be executed by the corresponding platform, such as executable files that are packaged on Windows to generate EXE. This article demonstrates the use of Pyinstaller to package a simple EXE program on the Windows platform.



Second, the original script content is as follows:

1. Generate a note color ball code as follows:

Def caiseqiu (num=1):                       num = int (num)     p =  1    with open ("tmp", ' W ')  as f:         while p <= num:             LAN = []            L =  []            while len (L)  <= 5:                 L =  Lan.append (Random.randrange (1, 34))                  l = sorted (Set (LAN))                  blue = random.randrange (1, 17)              print ("Red ball: %s,  Blue ball:  %s")  %  (L, blue)                p += 1if __name__  ==  "__main__":    caiseqiu ()

Execution will be generated as follows:

Red ball: [10, 13, 20, 24, 28, 29], Blue ball: 9


Third, the use of Pyinstaller packaged into executable EXE program

1. Environment

Python2.7.13, in order to package into a graphical executable program needs to install the Wxpython module, pip install Wxpython

A graphical executable program generates color ball.

2, the code is as follows:

#!/usr/bin/python# -*- coding=utf-8 -*-# by author san at  2016-03-03import randomimport sysimport wx# clears the generated color ball def onclear (event):     content. SetValue (")     def caiseqiu (event,num=1):     num = int (num)     p = 1    with open ("tmp", ' W ')  as f:         while p <= num:             LAN = []             L = []             while len (L)  <= 5:                 l = lan.append (Random.randrange (1, 34))         &nBsp;        l = sorted (Set (LAN))                  blue = random.randrange (1, &NBSP;17)             content. SetValue ("Red ball: %s,  Blue ball:  %s"  %  (l, blue))              p += 1app = wx. APP () frame = wx. Frame (none, title= "Color ball Generator v1.0",  size= (420, 350)) panel = wx. Panel (frame) sbox = wx. Boxsizer ()  vbox = wx. Boxsizer (WX. VERTICAL)   content = wx. Textctrl (panel) btn1 = wx. Button (panel, label= "Generate") btn2 = wx. Button (panel, label= "clear") Sbox.add (btn1, proportion=1, flag=wx. Expand | wx. all, border=5) Sbox.add (btn2, proportion=1, flag=wx. Expand | wx. All, border=5) Vbox.add (sbox, proportion=1, flag=wx. Expand | wx. all, border=5) Vbox.add (content, proportion=5, flag=wx. Expand | wx. all, border=5) btn1. Bind (WX. Evt_button, caiseqiu) btn2. Bind (WX. Evt_button, onclear) panel. Setsizer (VBox) frame. Show () app. Mainloop ()

Save As Caiseqiu.pyw double-click Execute

650) this.width=650; "title=" 1.png "src=" https://s3.51cto.com/wyfs02/M02/9B/C8/ Wkiom1lnftgwfrqsaaamebrxuum699.png-wh_500x0-wm_3-wmp_4-s_792384647.png "alt=" Wkiom1lnftgwfrqsaaamebrxuum699.png-wh_50 "/>

Description: The python script for this pyw suffix needs to be installed on a python system to execute, but it cannot be executed on a system that does not have a Python environment installed, so it needs to be pyinstaller packaged as an EXE file


3, Pyinstaller packaging into Caiseqiu.exe

Put Caiseqiu.pyw into a non-English directory (c:\mypythonexe\), open cmd-->cd c:\mypythonexe

650) this.width=650; "title=" 2.png "src=" https://s1.51cto.com/wyfs02/M02/9B/C8/wKiom1lnF5iz4Q02AAAWLucZE4w637.png "alt=" Wkiom1lnf5iz4q02aaawlucze4w637.png "/>


Execution: pyinstaller-f-W caiseqiu.pyw a message similar to the following appears

3845 info:building COLLECT Out00-collect.toc completed successfully.

Indicates that the package is successful, and the following information is available in the directory

 c:\mypythonexe's Directory

2017/07/13  14:46    <DIR>         .
2017/07/13  14:46    <DIR>         .
2017/07/13  14:46    <DIR>          Build
2017/07/12  18:32             1,264 Caiseqiu.pyw
2017/07/13  14:46                873 caiseqiu.spec
2017/07/13  14:46    <DIR>           Dist
                2 files           2,137 bytes
                4 directories   4,577,239,040 free bytes


In the Dist directory there will be a caiseqiu.exe as follows:

650) this.width=650; "title=" 3.png "src=" https://s5.51cto.com/wyfs02/M01/9B/C8/ Wkiom1lngsayx5lnaabszeah-cs777.png-wh_500x0-wm_3-wmp_4-s_4186271853.png "alt=" Wkiom1lngsayx5lnaabszeah-cs777.png-wh_50 "/>


Double-click to do the following:

650) this.width=650; "title=" 4.png "src=" https://s4.51cto.com/wyfs02/M02/9B/C8/ Wkiom1lngtlhej7vaaavcbradbi725.png-wh_500x0-wm_3-wmp_4-s_2368087414.png "alt=" Wkiom1lngtlhej7vaaavcbradbi725.png-wh_50 "/>

Point generation generates a column that clears the function.

Here we use the Wxpython Pyinstaller module to complete the Windows platform executable EXE package.

This article is from the "Learning, learning" blog, please be sure to keep this source http://dyc2005.blog.51cto.com/270872/1947108

Pyinstaller package Python script as EXE executable program

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.