Convert a Python script to an executable program in Windows

Source: Internet
Author: User

Your practical application of packaging Python scripts for py2exeProgramInterested? Do you know how to package Python scripts in py2exe? The two problems are as follows:ArticleI hope you will have a better understanding of it after browsing.

I. Introduction

Py2exe is an executable program (*. in this way, you can run this executable program on windows without installing python. Py2exe has been used to create wxpython, tkinter, PMW, pygtk, pygame, win32com client and server, and other independent programs. Py2exe is released under the open source license.

  • application scheme of Python scripts in other language Environments
  • advantages of the python scripting language in practical application
  • advantages of the vim compiler in Python scripts
  • linecount Of The Python script file. py-related code introduction
  • Python scripts and C ++ programs call each other

Ii. Install py2exe

Download and run the installer of the py2exe version corresponding to your installed python. This will install py2exe and the corresponding example; these examples are installed in the Lib \ Site-packages \ py2exe \ Samples Directory.

Iii. Usage of py2exe

If you have a file named myscript. you want to convert the Python script of Py to an executable program running on Windows and run it on a Windows system without Python installed, first, you should write a setup script for the release program, such as mysetup. PY, insert the statement import py2exe before the setup function.

An example of mysetup. py is as follows:

  1. # mysetup. PY
  2. from distutils. core import setup
  3. Import py2exe
  4. Setup ( Console = ["Myscript. py"])  

Run mysetup. py as follows:

  1. Python mysetup. py py2exe

Upload these files.

If your myscript. if the compiled C extension module is used in The py script, these modules will be copied to sub-directories. Similarly, all DLL files are required at runtime, besides system DLL files.
The files in the DIST subdirectory contain what is necessary for your program. You should publish all the content in this subdirectory together.

By default, py2exe creates the following necessary files in the DIST directory:

1. One or more EXE files.

2. Python ##. DLL.

3. Several. PYD files, which are compiled extensions and required by the EXE files. With other. DLL files, these. DLL files are required by. PYD.

4. A library.zip file that contains compiled Python modules such as. PyC or. Pyo

Mysetup.pycreated a console myscript.exe program. If you want to create a program in the graphic user field, you only need to set mysetup. console = ["myscript. replace py "] with Windows = [" myscript. PY. Py2exe can create multiple EXE files at a time. You need to pass the list of these Python script files to the console or Windows keyword parameters.

This is useful if you have several associated scripts. Run the following command to display all command line labels of the py2exe command.

The above is an introduction to how to use py2exe to package the Python script. I hope you will get something.

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.