如何克服此_tkinter.Tcl错误?

时间:2018-10-22 14:28:19

标签: python linux tkinter

我目前正在尝试在linux中运行以下代码,以便能够在图像的特定部分周围绘制框。当我运行代码时,收到以下错误,我对如何正确解决此问题感到困惑。我在学校的服务器上,因此无法访问sudo,除非我为学校提交了安装任何东西的票!任何指导将不胜感激

import os
import matplotlib.pyplot as plt
import cv2
from matplotlib.widgets import RectangleSelector
from generate_xml import write_xml

# global constants
img = None
tl_list = []
br_list = []
object_list = []

# constants
image_folder = 'images'
savedir = 'annotations'
obj = 'anomaly'


def line_select_callback(clk, rls):
    global tl_list
    global br_list
    global object_list
    tl_list.append((int(clk.xdata), int(clk.ydata)))
    br_list.append((int(rls.xdata), int(rls.ydata)))
    object_list.append(obj)


def onkeypress(event):
    global object_list
    global tl_list
    global br_list
    global img
    if event.key == 'q':
        print(object_list)
        write_xml(image_folder, img, object_list, tl_list, br_list, savedir)
        tl_list = []
        br_list = []
        object_list = []
        img = None
        plt.close()


def toggle_selector(event):
    toggle_selector.RS.set_active(True)


if __name__ == '__main__':
    for n, image_file in enumerate(os.scandir(image_folder)):
        img = image_file
        fig, ax = plt.subplots(1)
        mngr = plt.get_current_fig_manager()
        mngr.window.setGeometry(250, 120, 1280, 1024)
        image = cv2.imread(image_file.path)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        ax.imshow(image)

        toggle_selector.RS = RectangleSelector(
            ax, line_select_callback,
            drawtype='box', useblit=True,
            button=[1], minspanx=5, minspany=5,
            spancoords='pixels', interactive=True
        )
        bbox = plt.connect('key_press_event', toggle_selector)
        key = plt.connect('key_press_event', onkeypress)
        plt.show()

跟踪:

   File "draw_box.py", line 50, in <module>
    fig, ax = plt.subplots(1)
  File "/cm/shared/apps/tensorflow/1.4/python3/GPU/lib/python3.6/site-packages/matplotlib/pyplot.py", line 1198, in subplots
    fig = figure(**fig_kw)
  File "/cm/shared/apps/tensorflow/1.4/python3/GPU/lib/python3.6/site-packages/matplotlib/pyplot.py", line 548, in figure
    **kwargs)
  File "/cm/shared/apps/tensorflow/1.4/python3/GPU/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 161, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "/cm/shared/apps/tensorflow/1.4/python3/GPU/lib/python3.6/site-packages/matplotlib/backends/_backend_tk.py", line 1044, in new_figure_manager_given_figure
    window = Tk.Tk(className="matplotlib")
  File "/cm/shared/apps/anaconda3/4.4.0/lib/python3.6/tkinter/__init__.py", line 2017, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
    /opt/anaconda1anaconda2anaconda3/lib/tcl8.5 /cm/shared/apps/tensorflow/1.4/python3/GPU/lib/tcl8.5 /cm/shared/apps/tensorflow/1.4/python3/lib/tcl8.5 /cm/shared/apps/tensorflow/1.4/python3/GPU/library /cm/shared/apps/tensorflow/1.4/python3/library /cm/shared/apps/tensorflow/1.4/python3/tcl8.5.18/library /cm/shared/apps/tensorflow/1.4/tcl8.5.18/library

这可能意味着Tcl安装不正确。

由于错误的最后一行指出Tcl的安装不正确,我需要学校重新安装它吗?

0 个答案:

没有答案