之前Pyinstaller打包失败,所以换成cx-Freeze打包。
官网写的很清楚。
最简单粗暴的打包是这样的,可执行文件和pyinstaller一样生成在dist文件夹里
例如:
1 2 3 4 5 6 7 8 9 10
| cxfreeze --script hello.py --target-dir dist
--script=要打包的主py文件 --init-script=开始启动的文件,如果没写绝对路径的话,会去cx_Freeze package的根目录里找 --base=NAME, --base-name=NAME --target-name=生成可执行文件的名字,不要包含路径 --target-dir=生成可执行文件所在目录,默认为dist --icon=图标 --shortcut-name=快捷方式的名字(MSI) --shortcut-dir=MSI安装包
|
如果不想出现控制台窗口的话:就加上
e.g.
1
| cxfreeze --script main.py --target-dir dist --base-name="win32gui"
|
只打包了main.py,其它文件没有被打包上。copy到
每次都要敲命令行非常麻烦,新建一个bat文件批量复制,例如:
1 2 3 4 5 6 7 8 9 10 11
| set "root_path=%~dp0" cxFreeze --script main.py --icon=%root_path%Assets\icons\logo_orange.ico --target-dir dist --base-name="win32gui" set exe_path=%root_path%dist XCOPY %root_path%\Assets\ %exe_path%\Assets\ /E /I XCOPY %root_path%\Temp\ %exe_path%\Temp\ /E /I XCOPY %root_path%\Templates\ %exe_path%\Templates\ /E /I XCOPY %root_path%\Views\ %exe_path%\Views\ /E /I XCOPY %root_path%\Sqlite\ %exe_path%\Sqlite\ /E /I XCOPY %root_path%\.venv\Lib\site-packages\sqlalchemy\ %exe_path%\lib\sqlalchemy\/E /I echo END! pause
|