【问题标题】:tkagg (python) DLL load failed: %1 is not a valid Win32 applicationtkagg (python) DLL 加载失败:%1 不是有效的 Win32 应用程序
【发布时间】:2016-04-11 15:37:25
【问题描述】:

我正在使用 tkinter 和 python 3.5 编写应用程序。我正在使用 64 位的 Windows 7。然而,看起来“import matplotlib.backends.tkagg as tkagg”正在引起麻烦。我试图在 anaconda 环境中工作,但也没有在那个环境中工作。有人可以帮我吗?

这是错误:

Traceback (most recent call last):
  File "C:\Users\michele.dellamea\Desktop\matplot\tkinterrr.py", line 4, in <module>
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
  File "C:\Users\michele.dellamea\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 13, in <module>
    import matplotlib.backends.tkagg as tkagg
  File "C:\Users\michele.dellamea\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\backends\tkagg.py", line 9, in <module>
    from matplotlib.backends import _tkagg
ImportError: DLL load failed: %1 is not a valid Win32 application.
[Finished in 1.3s with exit code 1]
[shell_cmd: python -u "C:\Users\michele.dellamea\Desktop\matplot\tkinterrr.py"]
[dir: C:\Users\michele.dellamea\Desktop\matplot]
[path: C:\ProgramData\Oracle\Java\javapath;c:\Program Files (x86)\AMD APP\bin\x86_64;c:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Skype\Phone\;C:\Users\michele.dellamea\AppData\Local\Programs\Python\Python35-32\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\michele.dellamea\AppData\Local\Continuum\Anaconda3;C:\Users\michele.dellamea\AppData\Local\Continuum\Anaconda3\Scripts;C:\Users\michele.dellamea\AppData\Local\Continuum\Anaconda3\Library\bin]

代码如下:

import matplotlib
matplotlib.use("TkAgg")

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
#import matplotlib.pylab as pylab

import tkinter as tk
from tkinter import ttk #css for tkinter



LARGE_FONT = ("Verdana", 12)


class SeaofBTCapp(tk.Tk):

    def __init__(self, *args, **kwargs): #args all var, kwargs all dict

        tk.Tk.__init__(self, *args, **kwargs)

        tk.Tk.iconbitmap(self, default="agnul.jpg")
        tk.Tk.wm_title(self, "Sea of BTC client")

        container = tk.Frame(self) #frame hedge window
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (StartPage, PageOne, PageTwo, PageThree):
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky="nsew") #you specify all grid

        self.show_frame(StartPage)

    def show_frame(self, cont):

        frame = self.frames[cont] # key
        frame.tkraise()

def qf(stringtoprint):
    print(stringtoprint)

class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Start Page", font=LARGE_FONT) #Label class label object
        label.pack(pady=10, padx=10)

        button1 = ttk.Button(self, text="Visit Page 1", command=lambda: controller.show_frame(PageOne))
        button1.pack()

        button2 = ttk.Button(self, text="Visit Page 2", command=lambda: controller.show_frame(PageTwo))
        button2.pack()

        button3 = ttk.Button(self, text="Graph Page", command=lambda: controller.show_frame(PageThree))
        button3.pack()

class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Page 1", font=LARGE_FONT) #Label class label object
        label.pack(pady=10, padx=10)

        button1 = ttk.Button(self, text="Back to Home", command=lambda: controller.show_frame(StartPage))
        button1.pack()

        button2 = ttk.Button(self, text="Page 2", command=lambda: controller.show_frame(PageTwo))
        button2.pack()

class PageTwo(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Page 2", font=LARGE_FONT) #Label class label object
        label.pack(pady=10, padx=10)

        button1 = ttk.Button(self, text="Back to Home", command=lambda: controller.show_frame(StartPage))
        button1.pack()

        button2 = ttk.Button(self, text="Page 1", command=lambda: controller.show_frame(PageOne))
        button2.pack()

class PageThree(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Graph Page", font=LARGE_FONT) #Label class label object
        label.pack(pady=10, padx=10)

        button1 = ttk.Button(self, text="Back to Home", command=lambda: controller.show_frame(StartPage))
        button1.pack()

        f = Figure(figsize=(5,5), dpi=100)
        a = f.add_subplot(111)
        a.plot([1,2,3,4,5,6,7,8],[5,6,1,3,8,9,3,5])

        canvas = FigureCanvasTkAgg(f, self)
        canvas.show()
        canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)

        toolbar = NavigationToolbar2TkAgg(canvas, self)
        toolbar.update()
        canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)


app = SeaofBTCapp()
app.mainloop()

【问题讨论】:

    标签: python-3.x matplotlib tkinter tkinter-canvas


    【解决方案1】:

    使用dependency walker 打开文件C:\Program Files\Python 3\Lib\site-packages\matplotlib\backends\backend_tkagg.pyd 并查找缺少哪个 dll 以及预期的位置.

    我遇到了同样的问题,后端查找 pythonFolder\Lib\site-packages\matplotlib\backend 文件夹中缺少但实际存在的 msvcp140.dll 文件在 pythonFolder\Lib\site-packages\matplotlib 文件夹中。所以我将它复制到正确的文件夹中以使其工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-08
      • 2012-03-05
      • 2014-01-02
      • 2013-01-15
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 2014-12-25
      相关资源
      最近更新 更多