py2exe打包pyqt程序
生活随笔
收集整理的這篇文章主要介紹了
py2exe打包pyqt程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
前幾天看到鉑金小鳥寫的 osc for PC 客戶端,python和css、js、html幾種語言寫的windows程序,我非常感興趣。于是自己摸索了一下windows平臺下不用C++和C#寫帶UI的程序。用到的軟件
py2exe py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation. 說白了,py2exe就是讓那些沒有安裝python的用戶也能執行python寫的程序。它的作用就是打包python成二進制文件。至于ubuntu等系統如何打包,我就不知道了。我安裝的版本是: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. 簡而言之,pyqt就是一個工具,讓python也能調用qt的強大的UI庫文件。命令行界面
安裝好兩個工具后,先寫一個hello world。 在你的工作目錄下,新建一個文件名為 hello.py,內容是: print "Hello World!" 然后在當前目錄下新建一個文件名為setup.py,內容是: from distutils.core import setup import py2exesetup(console=['hello.py'])#注意此處的console關鍵字,如果是帶有UI界面的軟件,那么為windows 然后在命令行中執行以下語句,配置編譯環境 python setup.py install 最后執行以下語句,打包程序 python setup.py py2exe 此處如果遇到錯誤: File "form1.pyc", line 11, in ?File "qt.pyc", line 9, in ?File "qt.pyc", line 7, in __load ImportError: No module named sip 參考 http://www.py2exe.org/index.cgi/Py2exeAndPyQt,我們可以知道修改命令為: python setup.py py2exe --includes sip 即可。當然文中也提到了其他方法。 你會發現當前目錄下多了build和dist文件夾,cd到dist文件夾,然后hello.exe即可看到令人激動的"Hello World!"了。切忌不要直接點擊hello.exe執行,以為會一閃而過,啥也沒有。而且即使程序錯了,你也不知道,我也幫不了你了。。。漂亮的UI界面
在你的程序目錄下,新建一個文件,名為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_()) 至于為什么這樣寫,詳細解析見: http://jimmykuu.sinaapp.com/static/PyQt4_Tutorial/html/first_programs.html 把setup.py改為 import py2exe import sysfrom distutils.core import setupsetup(windows=['windows.py'])#看清楚了此處是windows,如果為console,你會看到難看的命令行界面在UI的后面。。。 然后分別執行 python setup.py py2exe python setup.py py2exe --includes sip?
參考:
- [1].? http://git.oschina.net/fantsme/oschina-for-pc?
- [2].? http://www.riverbankcomputing.co.uk/software/pyqt/intro?
- [3].? http://jimmykuu.sinaapp.com/static/PyQt4_Tutorial/html/index.html
- [4] . http://www.py2exe.org/index.cgi/Tutorial
- [5] http://www.pythoner.com/111.html#comment-2460
轉載于:https://my.oschina.net/itfanr/blog/195694
總結
以上是生活随笔為你收集整理的py2exe打包pyqt程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 浅析laravel门面原理与实现
- 下一篇: 说话人识别