简体   繁体   English

如何为pyqt项目创建Windows安装程序

[英]How to create windows installer for pyqt project

How can I convert my python program with Qt for GUI to .exe file?? 如何将我的python程序与Qt for GUI转换为.exe文件?

I want to make an installation file for my python source code 我想为我的python源代码制作一个安装文件

First part : "How can I convert my python program with Qt for GUI to .exe file??" 第一部分:“如何将我的python程序与Qt for GUI转换为.exe文件?”

You can use PyInstaller, which supports python 2.2 - 2.7 and it has a hook system for including Qt with all dlls and plugins. 您可以使用PyInstaller,它支持python 2.2 - 2.7,并且它有一个钩子系统,用于将Qt包含在所有dll和插件中。

You can use also : 你也可以使用:

  • bbfreeze bbfreeze
  • cxfreeze cxfreeze
  • py2exe (pretty old) py2exe(很旧)
  • esky (a wrapper of all the above except PyInstaller) esky(除了PyInstaller之外的所有上面的包装)

Basically all this systems have a definition file to handle and produce the binary package. 基本上所有这些系统都有一个定义文件来处理和生成二进制包。 For instance, esky has a setup.py (which is a distutil file) to produce the package : 例如,esky有一个setup.py(这是一个distutil文件)来生成包:

from esky import bdist_esky
from distutils.core import setup

setup(name="appname",
      version="1.2.3",
      scripts=["appname/script1.py","appname/gui/script2.pyw"],
      options={"bdist_esky":{"includes":["mylib"]}},
     )

Than you can call "python setup.py bdist_esky" 比你可以调用“python setup.py bdist_esky”

For PyInstaller the thing is pretty different. 对于PyInstaller来说,事情是完全不同的。 From console, cd in PyInstaller folder : 从控制台,在PyInstaller文件夹中的CD:

python Makespec.py  [options] script.py

This produce a spec file with all the options to package your script. 这将生成一个spec文件,其中包含打包脚本的所有选项。 You can also modify this file with an editor. 您也可以使用编辑器修改此文件。

python Build.py  script.spec

This analyzes and builds your exe (or os binary equivalent). 这将分析并构建您的exe(或os二进制等效项)。

Second part : "I want to make an installation file for my python source code" 第二部分:“我想为我的python源代码制作一个安装文件”

You have to use NSIS, InnoSetup, BitRock Installer, IzPack or equivalent to produce a platform installer. 您必须使用NSIS,InnoSetup,BitRock Installer,IzPack或同等产品来生成平台安装程序。 So you have to take the binary result produced on the first part and package it for os distribution. 因此,您必须获取在第一部分上生成的二进制结果并将其打包以进行os分发。 Almost all the installer systems are thought for Windows systems. 几乎所有的安装程序系统都适用于Windows系统。 Cross platform : Zero Install, IzPack ... If you use IzPack you can have a cross platform installer paying the price of including a jvm. 跨平台:零安装,IzPack ......如果您使用IzPack,您可以让跨平台安装程序支付包含jvm的价格。

Using Py2Exe is the most suitable choice here. 使用Py2Exe是最合适的选择。

PY2EXE Binaries : http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/ PY2EXE二进制文件: http//sourceforge.net/projects/py2exe/files/py2exe/0.6.9/

Usage : 用法:

  1. Create a new setup python file: from distutils.core import setup 创建一个新的安装python文件:来自distutils.core导入设置

import py2exe 导入py2exe

setup(console=['Your python script absolute path']) setup(console = ['你的python脚本绝对路径'])

  1. Save this file. 保存此文件。

  2. Goto Command Prompt and change directory where the setup.py file is saved. 转到命令提示并更改保存setup.py文件的目录。

  3. Run the command : [python < your python script name_to be converted in exe > py2exe] 运行命令:[python < 你的python脚本name_to在exe中转换 > py2exe]

I cannot post the images as I don't have 10 reputations to post more than two links. 我无法发布图片,因为我没有10个声誉来发布两个以上的链接。 Please comment if any help required. 如果需要任何帮助,请评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM