Python使用cx_Freeze库生成msi格式安装文件的方法

yipeiwu_com6年前Python基础

本文实例讲述了Python使用cx_Freeze库生成msi格式安装文件的方法。分享给大家供大家参考,具体如下:

①.需要在目录下面创建一个文件 。setup.py

②.写入代码:

import sys
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r'C:\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Python36-32\tcl\tk8.6'
include_files=[
  r'C:\Python36-32\DLLs\tcl86t.dll',
  r'C:\Python36-32\DLLs\tk86t.dll'
]
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"],"include_files":include_files}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
  base = "Win32GUI"
setup(name="video1",#打完包后取的名字
   version="2.1",#版本
   description="aaaaa",#描述
   options={"build_exe": build_exe_options},
   executables=[Executable("video.py", base=base)])

③.命令:

python setup.py bdist_msi   生成安装包以及直接运行的exe文件

python setup.py build       生成exe可执行程序

注:此处使用的cx_Freeze库可使用pip命令安装:

pip install cx_Freeze

此外,若使用Python2.7环境下安装时提示Python error: Microsoft Visual C++ 9.0 is required ,则需要安装一个Micorsoft Visual C++ Compiler for Python 2.7 的包,即可解决问题。

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总

希望本文所述对大家Python程序设计有所帮助。

相关文章

PyQt5实现从主窗口打开子窗口的方法

PyQt5实现从主窗口打开子窗口的方法

1.在Qt Designer中设计两个简单窗口 2.将.ui文件转换成.py文件 3.新建**.py文件 #-*- coding:utf-8 -*- from PyQt5.QtWi...

python访问纯真IP数据库的代码

核心代码: #!/usr/bin/env python # -*- coding: utf-8 -*- from bisect import bisect _LIST1,...

Python实现的多线程http压力测试代码

本文实例讲述了Python实现的多线程http压力测试代码。分享给大家供大家参考,具体如下: # Python version 3.3 __author__ = 'Toil' imp...

python读写Excel表格的实例代码(简单实用)

python读写Excel表格的实例代码(简单实用)

安装两个库:pip install xlrd、pip install xlwt 1.python读excel——xlrd 2.python写excel——xlwt 1.读excel数据,...

Python实现删除列表中满足一定条件的元素示例

本文实例讲述了Python实现删除列表中满足一定条件的元素。分享给大家供大家参考,具体如下: 从列表中删除满足一定条件的元素。 如:删除一个列表中长度为0的元素,或者删除列表中同时是2和...