首页 > 解决方案 > 将 .py 文件转换为 .exe 文件

问题描述

我们在 .py 文件中导入了人脸识别模块,如何将该 .py 文件转换为可执行文件?我们还有一些 .txt 文件,我们为其提供了项目路径本身。如何将该本地路径更改为全局路径并转换为可执行文件?

标签: pythonmysqlopencvtkinterface-recognition

解决方案


可执行文件的步骤如下所示 - 安装cx_freeze然后创建文件setup.py并粘贴以下内容 -

build_exe_options = {"includes": ["tkinter"]}
base = None
if sys.platform == "win32":
    base = "Win32GUI"
from cx_Freeze import setup, Executable 

setup(name = "<name-of-executable-file.exe>" , 
version = "<your-version-number>" , 
description = "<suitable-description>" ,
options={"build_exe": build_exe_options},
executables = [Executable("<your-python-file.py>", base=base)]) 

python setup.py build在您的终端中运行。


推荐阅读