2016-05-16 57 views
0

我想將我的Python應用程序轉換爲可執行文件,我發現cx_Freeze最容易修改並將其用於我的需要。cx_Freeze無法找到QtDesigner框架

這是我setup.py腳本:

from cx_Freeze import setup, Executable 

includefiles = ['Leaderboard.txt'] 
includes = ['PyQt4.QtGui', 'PyQt4.QtCore', 'functools.partial', 'multiprocessing.Process', 'sys'] 


setup(
    name = 'App', 
    version = '1.0', 
    description = 'Description', 
    author = 'ShellRox', 
    options = {'build_exe': {'include_files':includefiles}}, 
    executables = [Executable('Project.py', copyDependentFiles=True)] 
) 

的完整代碼here


出於某種原因,我得到這個錯誤:

error: [Errno 2] No such file or directory: 'QtDesigner.framework/Versions/4/QtDesigner' 

完整的日誌here

但是我不完全肯定能問題是什麼,做了一些研究之後,我發現只有一個結果匹配我的問題,它不會在所有幫助(我已經刪除的包雖然)。

我還在includes中只添加子模塊,但它仍然沒有幫助,我猜測它不是在尋找模塊。

有一兩件事讓我奇怪的是,如果有跟我reseources.py文件關聯的東西。

我也嘗試將QtDesigner位置文件添加到路徑,它沒有更新任何其他進程。

問題:

問題是什麼?我怎樣才能黑名單它cx_Freeze所以它不會搜索QtDesigner框架(如果不是很有用),或者我是否需要在路徑中添加的位置,以便可以尋找Qt設計(如果是這樣,則路徑會在哪裏?)。

回答

0

cx_Freeze有一個選項來排除二進制文件。使用該選項可以阻止搜索不需要的二進制文件。 從文檔

bin_excludes - list of names of files to exclude when determining dependencies of binary files that would normally be included; note that version numbers that normally follow the shared object extension are stripped prior to performing the comparison

添加該選項到你的setup.py文件build_exe選項裏面這樣

build_exe_options = { 
    "icon": iconPath, 
    "packages": packages, 
    "includes": includes, 
    "include_files": include_files, 
    "excludes": excludes, 
    "optimize": True, 
    "bin_excludes": ["QtDesigner"], 
    } 

但是,如果你的代碼實際上需要一個可執行文件?如果您使用'otool'查看依賴關係,您可能會發現PySide.QtUiTools模塊需要qtdesigner。

$ otool -L ~/lib/python2.7/site-packages/PySide/QtUiTools.so 
/lib/python2.7/site-packages/PySide/QtUiTools.so: 
    @rpath/libpyside-python2.7.1.2.dylib (compatibility version 1.2.0, current version 1.2.2) 
    /usr/local/lib/QtDesigner.framework/Versions/4/QtDesigner (compatibility version 4.8.0, current version 4.8.6) 
    /usr/local/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.6) 
    /usr/local/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.6) 
    @rpath/libshiboken-python2.7.1.2.dylib (compatibility version 1.2.0, current version 1.2.2) 
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0) 
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) 

所以你最好找地方QtDesigner位於並使用「install_name_tool」搜索路徑更改爲QtUiTools.so模塊的正確位置。