Introduction to the conversion from a Python script to an executable program in windows

Source: Internet
Author: User

Are you interested in the actual application of py2exe packaging Python scripts? Do you know how to package Python scripts in py2exe? These two questions will be mentioned in the following articles. I hope you will have a better understanding of them 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 solution of Python scripts in other language Environments
  • Introduction to the advantages of python script in practical application
  • The five advantages of the vim compiler in Python scripts
  • Code about LineCount. py in the Python script file
  • 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.