基於cx_freeze編譯PyQt4程式(numpy & scipy),cx_freezepyqt4

來源:互聯網
上載者:User

基於cx_freeze編譯PyQt4程式(numpy & scipy),cx_freezepyqt4

當開發完成PyQt4程式後,需要提供給他人使用,這時最好的辦法是將Python程式編譯成exe檔案。

通常我採用cx_freeze完成這個工作,即編寫setup.py檔案,執行python setup.py build即可。

(1) 對於一般的PyQt4程式,setup.py內容如下:

 1 import sys 2  3 from cx_Freeze import setup, Executable 4  5 base = None 6 if sys.platform == 'win32': 7     base = 'Win32GUI' 8      9 options = {10     'build_exe': {11             'includes': ['atexit'],12             'excludes': ['Tkinter',13                          'collections.sys',14                          'collections._weakref']15     }16 }17 18 setup(19         name="程式名",20         version="版本號碼",21         description="",22         options=options,23         executables=[Executable("主程式絕對路徑", base=base,24                                 icon="表徵圖絕對路徑")])

(2) 當使用numpy後,則setup.py修改為:

 1 import sys 2  3 from cx_Freeze import setup, Executable 4  5 base = None 6 if sys.platform == 'win32': 7     base = 'Win32GUI' 8      9 options = {10     'build_exe': {11             'includes': ['atexit',12                          'numpy'],13             'excludes': ['Tkinter',14                          'collections.sys',15                          'collections._weakref']16     }17 }18 19 setup(20         name="程式名",21         version="版本號碼",22         description="",23         options=options,24         executables=[Executable("主程式絕對路徑", base=base,25                                 icon="表徵圖絕對路徑")])

(3) 當使用scipy後,利用cx_freeze編譯時間會出現Import Error: No module named 'scipy'。

這時需要將cx_Freeze檔案夾下的hooks.py的第548行代碼"finder.IncludePackage("scipy.lib")"改為"finder.IncludePackage("scipy._lib")"。

相應的setup.py修改如下:

 1 import sys 2 import numpy # 一定要有,否則會出現_ufuncs錯誤 3  4 from cx_Freeze import setup, Executable 5  6 base = None 7 if sys.platform == 'win32': 8     base = 'Win32GUI' 9     10 options = {11     'build_exe': {12             'packages': ['scipy'], # 重要13             'includes': ['atexit',14                          'numpy',15                          'scipy'],16             'excludes': ['Tkinter',17                          'collections.sys',18                          'collections._weakref']19     }20 }21 22 setup(23         name="程式名",24         version="版本號碼",25         description="",26         options=options,27         executables=[Executable("主程式絕對路徑", base=base,28                                 icon="表徵圖絕對路徑")])

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.