要将 Python 脚本打包成可执行文件 (.exe),可以使用 PyInstaller 这个第三方库。
安装 PyInstaller 库:
pip install pyinstaller
在命令行中切换到包含 Python 脚本的目录。
在命令行中运行以下命令来打包 Python 脚本:
pyinstaller --onefile filename.py
这将生成一个名为filename.exe的可执行文件。--onefile选项指定打包成一个单独的可执行文件。打包完成后,可以在命令行中运行python filename.exe来运行 Python 脚本。如果使用的是 Windows 操作系统,可能需要将 PyInstaller 库安装到 Windows 的二进制文件目录中 (通常是 C:\Windows\System32)。否则,Python 脚本将无法正常运行
问chatGPT
众所周知,Python脚本不能在没有安装Python的机器上运行,需打包成可脱离python环境直接运行的.exe文件方便其他同学使用,目前比较常见的打包exe方法都是通过Pyinstaller来实现。