Case tutorial of three Python packaging methods

Time:2021-10-24

Cxfree, pyinstaller and py2exe

At present, there are three free Python packaging tools available on the Internet: py2exe, pyinstaller and Cx_ Freeze。 The latest version of pyinstaller only supports Python 2.7, and the development of py2exe plans to support Python 3. X, but it has not been completed yet. Only CX_ Freeze supports both Python 3. X and python 2. X. Personally, I also think cxfree is relatively simple and not easy to make mistakes.

Cxfreeze has several file forms, MSI and WHL. MSI is the installation package. Double click the run and download address directlyhttp://sourceforge.net/projects/cx-freeze/files/4.3.2/ 。 WHL is a python installation package. Installation format:PIP install WHL file address, download address:      https://www.lfd.uci.edu/ ~gohlke/pythonlibs/

After installation, cxfree executes the script in Python_ Under home \ scripts

Cxfree package exe format:

Python cxfree full path: the PY file to be packaged   — target-dir=

L for example: cxfreeze   D:/hello.py  — target-dir   D: / 123 or Python cxfree   D:/hello.py  — target-dir=D:/123

Steps:

        1. First, downloadThe corresponding version of Cx of Python installed on this machine_ Freeze package

msi: https://www.lfd.uci.edu/~gohlke/pythonlibs/

whl:  https://www.lfd.uci.edu/~gohlke/pythonlibs/

        2. Installation

WHL: PIP install WHL installation package

Or MSI double click Install

        3. After installation, generate CX in the scripts folder under the python installation directory_ Freeze related files.

CMD, enter the file directory, and then type

Cxfree -- version or Python cxfree -- version

If the following information is displayed, the installation is successful!

Next, you can package the python program.

4. Create a new Python program, such as hello.py

Run in the “C: \ Python 33 \ scripts” directory (that is, the file directory where the cxfree command is located):


cxfreeze D:/hello.py --target-dir D:/123  

Of course, this is a relatively simple program, so there are few dependent files. When more external packages are introduced and you want to generate only one. EXE file, you can use the following command:


cxfreeze D:/hello.py --target-dir D:/123 --no-copy-deps  

At this point, it is found that only one. EXE file is generated.

5. If you want to generate an installable package file, you need to use “distutils setup script”, that is, you need to create a setupy.py file.

Here, simply create a setup.py file to generate the installable package of the above hello.py file.

function:


python setup.py bdist_msi  

After successful execution, build and dist files will be generated in the “C: \ Python 33 \ scripts” directory.

The dist folder contains the installation package file of the hello.py program

The build folder contains the executable file of the hello.py program, that is, hello.exe

This is the end of this article about the case tutorial of three Python packaging exe methods. For more information about Python packaging exe methods, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!