2012-03-13 87 views
3

我想編一個簡單的腳本我用Python3和PyQt4的使用cx_Freeze寫,但我有,我只是無法弄清楚三個問題。編譯問題python3和PyQt4的與cx_freeze

  1. 我無法使圖標出現。我正在使用一個已編譯的資源文件,即導入一個包含資源的.py,並且我試圖按照建議here,將imageformats文件夾複製到我的項目文件夾,但似乎沒有任何工作。

  2. 我沒有使用包括tcl和ttk的severl python模塊,所以我將它們添加到excludes選項。但是,他們似乎仍然被添加。

  3. 當我試着使用base='Win32GUI'編譯運行exe文件創建引發了一個異常:'NoneType' has no attribute 'encoding'

我敢肯定,還有就是有毛病我安裝腳本,因爲cx_Freeze文檔不是很詳細,所以希望有人能指出這個問題。這是安裝腳本。我不會發布我正在編譯的腳本,因爲它的時間很長,但如果需要的話,我會嘗試創建一個簡明的測試版本。

from cx_Freeze import setup, Executable 

exe = Executable(
    script='cconvert.py', 
    base='Win32GUI' 
) 

options = dict(
    excludes=['curses', 'email', 'tcl', 'ttk'] 
) 

setup(
    name="Coord Convertor", 
    version="0.1", 
    description="A Coordinate converter from DMS to DD", 
    requires=['pyqt4 (>=4.8)', 'dtlibs (>=0.4.1)'], 
    data_files=['imageformats'], 
    executables=[exe], 
    options={'build-exe': options} 
) 
+0

新的文檔上Readthedocs - 請你來幫助我們改進:http://readthedocs.org/docs/cx_freeze/en/latest/ – 2012-03-13 12:47:18

+0

謝謝 - 我有實際上只是找到了它。不幸的是,它似乎也不能解決我的問題。如果我解決它們,我會添加到文檔中。 – aquavitae 2012-03-13 13:14:17

回答

3

(注意務必約1)

2:在選項= { '打造-EXE' ......,我認爲它需要build_exe(下劃線,而不是短跑)。

3:你是否試圖在任何地方訪問類似sys.stdout.encoding的東西?當您使用Win32GUI基礎時,sys.stdout將爲無。即使是一個print()調用也可能觸發該事件。

+0

Grr ...愚蠢的錯字。這是固定的。你已經解決了3,謝謝。我每次開始運行doctest,打印到stdout。所以現在它只是1. – aquavitae 2012-03-13 13:40:33

6

已解決。除了Thomas的指針之外,我還需要'imageformats'在選項下的'include-files'下,而不是'data_files'。我最後的劇本是這樣的:

from cx_Freeze import setup, Executable 

exe = Executable(
    script='cconvert.pyw', 
    base='Win32GUI' 
) 

options = dict(
    excludes=['curses', 'email', 'tcl', 'ttk', 'tkinter'], 
    include_files=['imageformats'] 
) 

setup(
    name="Coord Convertor", 
    version="0.1", 
    description="A Coordinate converter from DMS to DD", 
    requires=['pyqt4 (>=4.8)', 'dtlibs (>=0.4.1)'], 
    executables=[exe], 
    options={'build_exe': options} 
) 
+0

我發現QtSvg也需要在其他計算機上顯示圖標。確保這一點最簡單的方法是簡單地在代碼中的某處導入PyQt4.QtSvg。 – aquavitae 2012-04-11 11:49:20