简体   繁体   中英

How to create windows installer for pyqt project

How can I convert my python program with Qt for GUI to .exe file??

I want to make an installation file for my python source code

First part : "How can I convert my python program with Qt for GUI to .exe file??"

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.

You can use also :

  • bbfreeze
  • cxfreeze
  • py2exe (pretty old)
  • esky (a wrapper of all the above except 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 :

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"

For PyInstaller the thing is pretty different. From console, cd in PyInstaller folder :

python Makespec.py  [options] script.py

This produce a spec file with all the options to package your script. You can also modify this file with an editor.

python Build.py  script.spec

This analyzes and builds your exe (or os binary equivalent).

Second part : "I want to make an installation file for my python source code"

You have to use NSIS, InnoSetup, BitRock Installer, IzPack or equivalent to produce a platform installer. So you have to take the binary result produced on the first part and package it for os distribution. Almost all the installer systems are thought for Windows systems. Cross platform : Zero Install, IzPack ... If you use IzPack you can have a cross platform installer paying the price of including a jvm.

Using Py2Exe is the most suitable choice here.

PY2EXE Binaries : http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/

Usage :

  1. Create a new setup python file: from distutils.core import setup

import py2exe

setup(console=['Your python script absolute path'])

  1. Save this file.

  2. Goto Command Prompt and change directory where the setup.py file is saved.

  3. Run the command : [python < your python script name_to be converted in exe > py2exe]

I cannot post the images as I don't have 10 reputations to post more than two links. Please comment if any help required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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