2015-06-30 140 views
-1

我正在構建一個GUI,它可以將.txt或.xlsx文件作爲輸入,對它們執行一些操作並將結果作爲圖返回。我爲GUI使用Python 3.4和Tkinter 8.5。在Python 3.4中創建跨平臺GUI

它有一個用於選擇文件類型的下拉列表和一個用於打開對話框以選擇文件的按鈕。然後它將該文件的內容保存到同一目錄中的不同文件中。它還有一個退出程序的按鈕,一個文本框和一個標籤,我只是在玩,並沒有達到任何目的。

當我運行datagui.py文件時,GUI工作。不過,我也想製作一個跨平臺的文件,不需要Python來運行它。我使用cx_freeze爲此目的作出了一個exe和寫了下面的setup.py文件來構建它(cx_Freeze網站上提供過):

import sys 
from cx_Freeze import setup, Executable 

base = None 
if sys.platform == "win32": 
    base = "Win32GUI" 

setup( name = "datagui", 
     version = "0.1", 
     description = "My first GUI application", 
     executables = [Executable("datagui.py", base=base)]) 

當我嘗試運行datagui.exe文件地處...\build\exe.win-amd64-3.4目錄中,我收到以下錯誤:

--------------------------- 
cx_Freeze: Python error in main script 
--------------------------- 
Traceback (most recent call last): 
    File "C:\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module> 
    exec(code, m.__dict__) 
    File "datagui.py", line 3, in <module> 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_and_load 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible 
    File "C:\Users\Anish\Desktop\DR. DIXON\Data Analysis\python codes\dataselect.py", line 3, in <module> 
    from pylab import * 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_and_load 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible 
    File "C:\Anaconda3\lib\site-packages\pylab.py", line 1, in <module> 
    from matplotlib.pylab import * 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_and_load 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible 
    File "C:\Anaconda3\lib\site-packages\matplotlib\pylab.py", line 274, in <module> 
    from matplotlib.pyplot import * 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_and_load 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible 
    File "C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 109, in <module> 
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() 
    File "C:\Anaconda3\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup 
    globals(),locals(),[backend_name],0) 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_and_load 
    File "c:\Python\64-bit\3.4\lib\importlib\_bootstrap.py", line 2224, in _find_and_load_unlocked 
ImportError: No module named 'matplotlib.backends.backend_qt4agg' 

我在做什麼錯在這裏?

+0

您正在使用matlplotlib? – Rishav

+0

「我也想製作一個跨平臺的可執行文件」。但是Linux和Mac無法運行可執行文件。 – Kevin

+0

我在一個單獨的程序中使用了matplotlib和numpy,我導入了pylab。我將部分代碼複製到現在正在使用的單獨模塊中,並且此代碼使用numpy,但不使用matplotlib。你認爲這可能是問題嗎? – Anish

回答

1

您可能想要查看您的matplotlib配置。

See this previous answer on matplotlib import

您需要指明要matplotlib實現後端的類型。

import matplotlib 
matplotlib.use("Agg") 

http://matplotlib.org/users/customizing.html

+0

謝謝,這解決了我的問題,我想我不需要導入pylab,所以只導入numpy的作品,我的GUI現在可以從exe中運行了。 – Anish

+0

不客氣:)如果你可以把這個標記爲你接受的答案,我感謝你。 –