English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Detailed Explanation of Methods to Package Python Executable Files

This article describes the method of packaging executable files in Python. Shared for everyone's reference, as follows:

Python programs need to depend on the Python libraries installed on the local machine. If you want to run them on a machine without Python installed, you need to package and distribute them. Currently, there are two very useful tools: PyInstaller and py2exe. The py2exe application is for Windows, while PyInstall can be used on Windows, Linux, and Mac OS X.

Here is only one segment of py2Instance code for exe packaging. (py2exe download address )

#coding=utf-8
from distutils.core import setup
import py2exe
includes = ["encodings", "encodings.*"]
#Other library files to include
options = {"py2exe":
  {
    "compressed": 1, #Compression
    "optimize": 2,
    "ascii": 1,
    "includes": includes,
    "bundle_files": 1 #All files packed into an exe file
  }
}
setup ()
  options = options,
  zipfile=None,  #do not generate library.zip file
  console=[{"script": "main.py", "icon_resources": [(1, "Q.ico")] }]#Source files, program icon
)

If the above source code is saved as mysetup.py, the packaging command is: python mysetup.py py2exe.

PS: Using Enigma Virtual Box can also make Py2The single file produced by exe packaging is more perfect. Enigma Virtual Box can be downloaded from this site: https://www.oldtoolbag.com/softs/425055.html

Two instances used:

(1)Background running

#coding=utf-8
from distutils.core import setup
import py2exe
includes = ["encodings", "encodings.*"]
#Other library files to include
options = {"py2exe":
  {
    "compressed": 1, #Compression
    "optimize": 2,
    "ascii": 1,
    "includes": includes,
    "bundle_files": 1 #All files packed into an exe file
  }
}
setup ()
  options = options,
  zipfile=None,  #do not generate library.zip file
  windows=[{"script": "main.py" }]#source file
)

(2)and it must have a console window and cannot be packaged into an exe file. (walker is because it called the browser)

#coding=utf-8
from distutils.core import setup
import py2exe
setup(
  console = [{'script': "main.py"}],
  options={
      "py2exe":{
          "skip_archive": True,
          "unbuffered": True,
          "optimize": 2
      }
  }
)

PS: For information on packaging Python scripts into exe files using PyInstaller, please refer to the article on this site: https://www.oldtoolbag.com/article/88235.htm

Readers who are interested in more Python-related content can check the special topics on this site: 'Summary of Python File and Directory Operation Skills', 'Summary of Python Text File Operation Skills', 'Summary of Python URL Operation Skills', 'Summary of Python Image Operation Skills', 'Python Data Structures and Algorithms Tutorial', 'Summary of Python Socket Programming Skills', 'Summary of Python Function Usage Skills', 'Summary of Python String Operation Skills', and 'Classic Tutorial of Python入门与进阶'.

Hoping the content described in this article will be helpful to everyone's Python program design.

Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal responsibility. If you find any content suspected of copyright infringement, please send an email to notice#w3Please report any violations by sending an email to codebox.com (replace # with @) and provide relevant evidence. Once verified, this site will immediately delete the infringing content.