Python uses cxfree to package script files into executable programs

  I have tried to package Python scripts with pyinstall before, but I encountered many problems in the process of using pyinstall, such as too large volume of packaged files, too many irrelevant files in the root directory of packaged programs, and so on.

  So instead of pyinstaller, I use cxfree to package Python scripts. Without saying much, let’s get to the point.

1. Install CX_ Freeze:

  The version of Python I use is 3.8.8. I can install CX directly with pypi_ Freeze。

  Command: PIP install CX_ Freeze

  CX installed_ The version of freeze is 6.6. After installation, you can start to package the script. Let’s simply create a script file for packaging.

hello.py:

import datetime

Print (‘Hello, the current date and time are: ‘, datetime. Datetime. Now())

input()

I store this script in the pinstar folder under disk D

Next, we introduce two ways to package the above script as. Exe

  First, after win + R, enter CMD to enter the command line, and then CD   C: Enter the scripts directory in the python installation path.

Here, the path following the CD is the installation path of Python in my computer. Just replace this path with the path of Python in my computer. For example, if anaconda is used, the path can be changed to the path of scripts folder under anaconda.

  After the path is switched, use the command cxfree D:: (pinstarr) Hello. Py — target dir D:: (pinstarr) dist, and press enter

Read More: