Three tool methods to package the Py file into an EXE

Source: Internet
Author: User
Using Cx_freeze to package the py file into exe (picture and text) 2011-09-10 13:18:51 Tags: cx_freeze python pack to remove black window casual Wolf Dance original works, allow reprint, reprint, please be sure to hyperlink form to indicate the original source of the article, Author information and this statement. Otherwise, legal liability will be held. http://keliang.blog.51cto.com/3359430/661884

Python is a very, very good programming language, and its biggest feature is Cross-platform. Python programs can be used in almost every common platform, and most of them do not need to modify any code. However, Python has a bit of a flaw (this is due to its own nature of the decision, can not be called a flaw, but here is called it), that is the execution of Python programs must have an interpreter to participate. So how does the Python program work on a platform without an interpreter? It's simple to package a Python program as an EXE executable file.

There are three kinds of Python exe methods commonly used in Python, respectively, Cx_freeze,py2exe,pyinstaller. Py2exe is probably the most high-profile of the three, but at the same time its packaging quality is probably the worst one. Pyinstaller packing is good, but the operation is more complicated. So personally or recommend Cx_freeze.

First: Cx_freeze Download address: http://sourceforge.net/projects/cx-freeze/files/

Next, introduce the use method of Cx_freeze.

Step one: Check to see if the Cx_freeze is properly installed.

Run cmd, switch to Cxfreeze.bat, and then perform "cxfreeze-h" to see if it works

If the installation is correct, as shown in the figure

If the following picture appears, please check your Python installation path

Ways to modify paths

Open your Python installation folder, such as my Python installation folder in G disk, then open G:\python\Scripts\cxfreeze.bat with Notepad

As shown in figure

Modify the path to your own installation path

Then save, close Notepad, and check again to see if it is correct.

Step Two: If the installation is correct, then the next thing is very simple

Officially started packing, the order is: Cxfreeze hello.py--target-dir Dist

Command explanation: hello.py is the main file, startup file you want to package

Dist is the destination folder, the package will generate the Dist directory, which has the packaged executable file.

Note: You can specify only one module to package, that is, all. py files for the boot module cannot have Chinese characters, otherwise there will be an encoding exception. After publishing, the executable path cannot have Chinese (preferably with no spaces). Do not have the following judgment in the file that initiates execution, otherwise executable execution will have no effect.
if __name__ = = "__main__":
Main () package successful Picture:

Double-click the generated EXE file to use it is not very happy about it. It feels uncomfortable to have a dusky window at the back of the boot. Then you add a parameter to the build command. Example:

Cxfreeze hello.py--target-dir Dist--base-name=123 over. If you have additional requirements for the build, see:

Http://cx-freeze.sourceforge.net/cx_Freeze.html

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.