Home > Backend Development > Python Tutorial > How to package python projects into exe and installation packages

How to package python projects into exe and installation packages

WBOY
Release: 2023-04-30 11:55:06
forward
2605 people have browsed it

1. Packaging Flask project

1.1 Write your own Flask

How to package python projects into exe and installation packages

##1.2 Download pyinstaller

pip install pyinstaller
Copy after login
Optional parametersExampleDescription##-Fpyinstaller -F demo.py-Dpyinstaller -D demo.py-cpyinstaller -c demo.py-wpyinstaller -w demo .py-ppyinstaller -p D:\project\demo.py-i 1.3 Enter the project path and execute
# run.py 是flask项目的执行文件,app.run所在py文件
	pyinstaller -D run.py    
	
# 可以看到项目路径下有
	-build文件夹
	-dist文件夹:重要,下有run文件夹(py文件名字),有个run.exe(py文件的名字)
	-run.spec
  
# 把pro_flask这个文件夹,拷贝到dist下的run文件夹
	-因为flask项目有静态文件和html文件,如果不拷贝过去,静态文件和html文件会找不到
	-我们为了隐藏代码,可以把所有python的代码都删除,只留static和templates文件夹
Copy after login
Only generates a program demo.exe file in the dist folder, suitable for a module without multiple dependency .py files
The default option, in addition to the main program demo.exe, will also Many dependency files are generated in the dist folder. It is recommended to use this
Default option, only valid for windows, use the console
is only valid for windows, does not use the console
Set import path
# #pyinstaller -i D:\demo.ico demo.py Set a custom icon for the generated demo.exe file

1.4 Run exe and testHow to package python projects into exe and installation packages

# 到dist/run文件夹下,双击 run.exe,启动
如下图
# 浏览器访问
如下图
Copy after login

2. Use nsis The folder is packaged into a windows installation packageHow to package python projects into exe and installation packages

2.1 Download and install nsis

nsis: NSIS (Nullsoft Scriptable Install System) is an open source installer production program for Windows systems. It provides installation, Uninstall, system settings, file decompression and other functions. 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 into a windows installation package

2.2 Compress the run folder under the dist folder into a zipHow to package python projects into exe and installation packages

2.3 Use nsis to compress the package into a windows installation documentHow to package python projects into exe and installation packages

How to package python projects into exe and installation packages

How to package python projects into exe and installation packages

The above is the detailed content of How to package python projects into exe and installation packages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template