The Python program turns into an EXE executable program

Source: Internet
Author: User

Recently more and more like using Python to write tools. When used, the Discovery program internal Members Python installation directory is often different, if the bat double-click execution, often need to modify from the SVN down in the bat file Pythone.exe path. For planning, art or QA use, but also need to let them install Python and a variety of plug-ins, they can annoy you to death. Therefore, the PY file must be turned into an EXE file, and then double-click the dummy execution.


I learned that there are two commonly used kits: Py2exe and Pyinstaller, and I chose Pyinstaller. Here is a record of how to use it.


first, the last officer network download , http://www.pyinstaller.org/, recommended 32-bit 2.7 version, and then unzip.


Ii. methods of Use

Doc/manual.html wrote in detail, here is a brief talk about the most basic, commonly used functions.

1. cmd into the extracted Pyinstaller directory, execute the command format as follows:

Python pyinstaller.py [opts] program.py

Several common options include:
-D,--onedir creates a directory that contains EXE files and dependent files, which is the default option. (Create a folder name containing an executable name and all support files.) This is the default.)
-F,--onefile create an EXE file, all dependent files are packaged into this EXE file, this EXE will be relatively large, but I feel convenient to use. (Create a single executable file name (or name. exe or name. App).)
-C,--console,--nowindowed console, no interface, default options. (Set up a console subsystem to standard input/output at run time.) The default for both One-file and One-folder modes.)
-W,--windowed,--noconsole window no console. (On Windows and Mac OS X, don't create a console window at run time for Input/output. (this option was ignored for other operating systems.) On Mac OS X, this option triggers the creation of a OS x application bundle.)

For example: D:\soft\python\pyinstaller-2.1>python pyinstaller.py-c-F E:\work\unity\xxx\trunk\tools\excel2json\ excel2json.py
Error, dependent Pywin32


2. Install the PYWIN32. http://sourceforge.net/projects/pywin32/files/pywin32/, after downloading, double-click Install.


3. Execute again under CMD, D:\soft\python\pyinstaller-2.1>python pyinstaller.py-c-F E:\work\unity\xxx\trunk\tools\excel2json\ excel2json.py.

successfully generated exe!



The resulting target file is in the Pyinstaller directory.


P.S. Later found that the generated EXE could not be executed in the Chinese path. In this blog to see the reason, Pyinstaller in the process of UTF8 coding where there are bug,blog authors have modified their own to upload to GitHub, click the Open link, I tested 32-bit python2.7 available.


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.