python cx_Freeze安装详解、打包exe文件简解

最近想打包自己写的程序,前面用了Python pyinstaller,但是总会出现其他目录的.py文件找不到的问题,弄了一天,放弃了。现在试试Python cx_freeze。

  1. 安装:

pip install cx-freeze 安装。在安装时出现 error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools":……

查看资料要去https://www.lfd.uci.edu/~gohlke/pythonlibs/下载对应的Microsoft Visual C++ 14.0

下载对应的版本,cp37的意思是python37版(我用的版本)安装。

pip install D:\Program Files\下载\cx_Freeze-5.1.1-cp37-cp37m-win_amd64.whl

然后运行

pip install cx_freeze

发现已经安装好了,进入Python37\Lib\site-packages\路径发现有2个文件

Python37\Scripts路径下有

打开CMD,cd 到Python37\Scripts路径下运行

 python cxfreeze-postinstall

这会安装成功了吧!

cmd 运行

cxfreeze -h

失败!

'C:\Program' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

后来查看资料,发现要修改上图中的cxfreeze.bat文件,文件中就是python3以及cx_freeze的路径,启动python3,运行cx_freeze,并回显到控制台上,我发现我的python3安装在C:\Program Files路径下,而.bat文件不能读取空格(坑……),最后将路径用引号夸起来保存。

在次运行cxfreeze -h

Usage: cxfreeze [options] [SCRIPT]

Freeze a Python script and all of its referenced modules to a base
executable which can then be distributed without requiring a Python
installation.

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -O                    optimize generated bytecode as per PYTHONOPTIMIZE; use
                        -OO in order to remove doc strings
  -c, --compress        compress byte code in zip files
  -s, --silent          suppress all output except warnings and errors
  --base-name=NAME      file on which to base the target file; if the name of
                        the file is not an absolute file name, the
                        subdirectory bases (rooted in the directory in which
                        the freezer is found) will be searched for a file
                        matching the name
  --init-script=NAME    script which will be executed upon startup; if the
                        name of the file is not an absolute file name, the
                        subdirectory initscripts (rooted in the directory in
                        which the cx_Freeze package is found) will be searched
                        for a file matching the name
……
……
……

这个显示OK!

 

  2.打包

运行到脚本路径下

cxfreeze main.py --target-dir dist

在dist目录下生成这4个文件,将main.exe运行,闪退……

最后发现所有.py文件都不能有中文字符,否则会出现编码异常。完……

 

转载于:https://www.cnblogs.com/gexbooks/p/11270206.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值