py2exe package pyqt program

A few days ago to see the birds platinum written osc for PC clients , python and css, js, html windows programs written in several languages, I am very interested. So write their own way a bit with the UI program without C ++ and C # windows platform.

Software used

py2exe
py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.
To put it plainly, py2exe is to allow users who do not install the python can also execute programs written in python. Its role is to package python into a binary file. As for how to package ubuntu and other systems, I do not know. I installed version is: py2exe-0.6.9.win32-py2.7.zip pyqt
PyQt is a set of Python v2 and v3 bindings for Digia's Qt application framework and runs on all platforms supported by Qt including Windows, MacOS/X and Linux. PyQt5 supports Qt v5. PyQt4 supports Qt v4 and will build against Qt v5. The bindings are implemented as a set of Python modules and contain over 620 classes.
In short, pyqt is a tool that allows python can invoke powerful UI library qt's.

Command Line Interface

After installing both tools, the first to write a hello world. In your working directory, create a file named hello.py, which reads:
print "Hello World!"
Then create a file named setup.py in the current directory, which reads:
from distutils.core import setup
import py2exe

setup(console=['hello.py'])#注意此处的console关键字,如果是带有UI界面的软件,那么为windows
Then execute the following statement on the command line, configure the build environment
python setup.py install
Finally, execute the following statement Packager
python setup.py py2exe
If you encounter an error here:
File "form1.pyc", line 11, in ?
  File "qt.pyc", line 9, in ?
  File "qt.pyc", line 7, in __load
ImportError: No module named sip
Reference http://www.py2exe.org/index.cgi/Py2exeAndPyQt , we can modify the command to know:
python setup.py py2exe --includes sip
It can be. Of course, the text also mentions other methods. You will find more than the current directory, build and dist folders, cd to the dist folder, and then hello.exe exciting to see "Hello World!" A. Do not just click hello.exe avoid execution, I thought it would be fleeting, had nothing. And even if the program is wrong, you do not know, I can not help you. . .

Beautiful UI interface

In your application directory, create a file named windows.py:
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
app = QtGui.QApplication(sys.argv)

widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('windows UI')
widget.show()

sys.exit(app.exec_())
As for why this writing, a detailed analysis see: http://jimmykuu.sinaapp.com/static/PyQt4_Tutorial/html/first_programs.html the setup.py changed
import py2exe
import sys

from distutils.core import setup

setup(windows=['windows.py'])#看清楚了此处是windows,如果为console,你会看到难看的命令行界面在UI的后面。。。
And then were executed
python setup.py py2exe
python setup.py py2exe --includes sip

 

reference:

Reproduced in: https: //my.oschina.net/itfanr/blog/195694

Guess you like

Origin blog.csdn.net/weixin_34245169/article/details/91799626