Package python project into exe and installation package

1. Package Flask project

1.1 Write your own Flask

2.2 Download pyinstaller

pip install pyinstaller
Optional parametersExampleillustrate
-Fpyinstaller -F demo.pyOnly generate a program demo.exe file in the dist folder, suitable for a module without multiple dependent .py files
-Dpyinstaller -D demo.pyThe default option, in addition to the main program demo.exe, will also generate many dependency files in the dist folder. It is recommended to use this
-cpyinstaller -c demo.pyDefault option, only valid for windows, use console
-wpyinstaller -w demo.pyOnly valid for Windows, does not use the console
-ppyinstaller -p D:\project\demo.pySet import path
-ipyinstaller -i D:\demo.ico demo.pySet a custom icon for the generated demo.exe file

2.3 Enter the project path and execute

# is the execution file of the flask project, and the py file where is located
	pyinstaller -D    
# You can see that there are
	-build folder
	-dist folder: important, there is a run folder (name of py file) and run.exe (name of py file)
# Copy the pro_flask folder to the run folder under dist
	- Because the flask project has static files and html files, if you do not copy them, the static files and html files will not be found.
	-In order to hide the code, we can delete all python code, leaving only the static and templates folders

2.4 Run exe and test

# Go to the dist/run folder, double-click run.exe to start
As shown below
# Browser access
As shown below

2. Use nsis to package the folder into a windows installation package

2.1 Download and install nsis

nsis: NSIS (Nullsoft Scriptable Install System) is an open source installer production program for Windows systems. It provides functions such as installation, uninstallation, system settings, and file decompression. As its name indicates, NSIS uses its scripting language to describe the behavior and logic of the installation program.
Use nsis to package the run folder of dist just now into a windows installation package.

2.2 Compress the run folder under the dist folder into zip

2.3 Use nsis to make the compressed package into a windows installation file

Related Posts

Detailed explanation of UnitTest for Python interface automated testing

Solution to SSL failure reported during compilation and installation of python3.10

oculus quest2 gesture interaction

ImportError: cannot import name ‘Literal‘ from ‘typing‘ (D:\Anaconda\envs\tensorflow\lib\

Selenium practical application – realizing automatic playback of courses on Zhidao wisdom tree

Selenium simulation browser in Python

YOLO series — YOLOV7 algorithm (1): Use a custom data set to run through the YOLOV7 algorithm

You can learn the Vue slot as soon as you learn it. Do you really want to take a look at it? (use scaffolding)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>