2017-02-06 65 views
0

我想凍結一個基於控制檯的程序,它使用matplotlib.pyplot來生成並保存圖。 (我並不需要預覽或查看地塊,無論如何都保存之前他們。)這是我的setup.py腳本:問題與matplotlib和cx_freeze

from cx_Freeze import setup, Executable 
import os 

os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Anaconda3\\tcl\\tcl8.6" 
os.environ['TK_LIBRARY'] = "C:\\Program Files\\Anaconda3\\tcl\\tk8.6" 

setup(name='FLOUResence.exe', 
    version='0.1', 
    options = {"build_exe": {"packages":["pandas", "numpy", "scipy", "matplotlib"]} 
      }, 
executables = [Executable(script='caller.py', targetName='FLOUResence.exe', 
icon="icon.ico", base='Console')] 
) 

我可以編譯程序,但是當我運行繪圖模塊則返回以下錯誤:

This application failed to start because it could not find or load the Qt platform plugin "windows" in "".
Reinstalling the application may fix this problem.

從我可以告訴,因爲matplotlib要加載/使用Qt的圖形用戶界面,而是因爲它是一個控制檯應用程序cx_freeze不加載的Qt?這是對問題的正確解釋嗎?有關如何解決這個問題的任何想法?

回答

1

您需要將Qt平臺插件添加到您的分發目錄。試一試,將PyQt安裝的Library\plugins\platforms拷貝到您的package/dist目錄中。如果這對你有用,你可以在你的include_files構建選項中添加目錄。我使用的是miniconda,因此平臺目錄位於c:\miniconda\Library\plugins

setup(name='FLOUResence.exe', 
    version='0.1', 
    options = { 
     "build_exe": {"packages":["pandas", "numpy", "scipy", "matplotlib"], 
         "include_files": [r'c:\miniconda\Library\plugins\platforms']} 
    }, 
    executables = [Executable(script='caller.py', targetName='FLOUResence.exe', 
        icon="icon.ico", base='Console')] 
)