pyQT5 应用打包--(cx-Freeze)

 1 前言

  python中比较常用的python转exe方法有三种,

  来自其它博客: py2exe恐怕是三者里面知名度最高的一个,但是同时相对来说它的打包质量恐怕也是最差的一个。pyinstaller打包很好,但是操作工序较为复杂。so个人还是推荐cx_freeze。

 2 安装

使用PIP安装:

pip3 install cx-Freeze

 

 

2 打包方法一(setup.py)

cxfreeze官网: https://cx-freeze.readthedocs.io/en/latest/overview.html

比较好的例子:参考https://www.cnblogs.com/panfb/p/9623083.html

1 编写一个python 脚本叫做installer.py(也可以叫setup.py) ,内容如下

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).

#指定平台,如果base=None, 会生成控制台的形式,多了一个控制台
base = "win32gui"
if sys.platform == "win64":
    base = "Win64GUI"

setup(name="d:\gui",            
      version="8.1",
      description="application!",
      options={"build_exe": build_exe_options},
      executables=[Executable("main.py", base=base, targetName='main.exe')])

2 执行安装脚本

c:\Python36\python3.exe installer.py build

或者

c:\Python36\python3.exe installer.py install

 

2 结果:

在当前文件夹和 D:\gui文件夹下生产输出文件

 

 

 

双击mian.exe,可以执行运行,放到其他电脑运行,拷贝整个文件夹过去

 

 

问题一:

 问题原因: TestCase 是工程中的目录,mian.py中使用 如下方式引入

from TestCase.Production import *

解决,TestCase不是一个目录,不能不Cx_freeze识别,在TestCase夹中定义一个__ini__t_.py文件,将TestCase目录改为包就可以了;

 

2 打包方法二(命令行方式)

我没有成功

 

posted @ 2020-01-09 10:03  lxz_kongjian  阅读(826)  评论(1)    收藏  举报