py2exe packages Python programs into exe execution files under Windows

py2exe packages Python programs

1. Introduction to py2exe

py2exe is a script that converts Python to Windows **.exe program that can be executed independently on , so that you can run

py2exe已经用于创builtwxPython, Tkinter , Pmw, PyGTK, pygame, win32com client和server, 和其它的INDEPENDENT PROGRAM. py2exeIt is available under the original name.

2. Install the py2exe module

Run the following command

pip install py2exe

Insert image description here
As above, if Successfully installed is displayed, the installation is successful.

3. Use py2exe to package python programs

Or take the test.py file as an example to create a test.py file. The edited content is as follows:

# -*- coding:utf-8 -*-

print(123)
print('hello')
print("I'm a man")
print('''python is good!
I like python...''')

You also need to create a configuration script file named mysetup.py and edit the content as follows:

from distutils.core import setup
import py2exe

setup(console=["test.py"])

The file structure is as follows:
Insert image description here
Then run the command:python mysetup.py py2exe, press Enter to execute, As shown below:

Insert image description here

After running, a dist file path > installed. Python folder together. In this way, it can be run on a computer that does not have dist folder contains the published content. When publishing, you need to publish all the files in the mysetup.py

Insert image description here
Insert image description here
Copy the files in dist to ffff< on other computers The results of running in the a i=4> folder are as follows.
Insert image description here

4. py2exe publishes multiple files

When publishing multiple files, you only need to modify themysetup.py file. Take pyinstaller as an example to publish a multi-file use case file. mysetup.pyThe content of the file is modified as follows:

from distutils.core import setup
import py2exe

setup(console=[
    "test.py",
    "test2.py",
    "tool/test3.py"
])

Then runpython mysetup.py py2exe, and the same will be generated todist folder. It's just that a **.exe** file will be generated for each file.

Insert image description here
Insert image description here
By default, py2exe is in the directory dist Create these necessary files:

  • One or more exe files.
  • python##.dll。
  • .pyd files, which are compiled extensions required by exe files ; plus other *.dll* files, these *.dllare required by.pyd*.
  • A library.zip file that contains compiled purepython modules, such as: .pyc or .pyo

I would like to emphasize again: when publishing, you must publish all the files under the dist folder together. \color{red}{I emphasize again: When publishing, all files under the dist folder must be published together. }I emphasize again: when publishing, you must use distAll files under the folder can be published together.

Many related properties can also be set in this configuration script. For details, please refer to the official website or github-py2exe

The above is a record of my actual operations during use. I share it with you as a note and for your own subsequent review.


Previous article:pyinstaller packages Python programs into exe execution files under Windows

Guess you like

Origin blog.csdn.net/weixin_44131612/article/details/131848500