我正在尝试在LX桌面环境中的图标(.desktop)上运行python3脚本。它以前工作过,但现在由于某种原因它不能打开,但仍然在IDLE3中工作。所以,我输入" python3 oldtext.py"进入终端,得到了这些错误:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "oldtext.py", line 3, in <module>
from tkinter import *
File "/home/pi/Desktop/tkinter.py", line 13, in <module>
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 7, in <module>
from six.moves import tkinter_filedialog as FileDialog
File "/usr/lib/python3/dist-packages/six.py", line 89, in __get__
result = self._resolve()
File "/usr/lib/python3/dist-packages/six.py", line 108, in _resolve
return _import_module(self.mod)
File "/usr/lib/python3/dist-packages/six.py", line 79, in _import_module
__import__(name)
ImportError: No module named 'tkinter.filedialog'; 'tkinter' is not a package
但是当我尝试安装它时,它已经安装了(tkinter)...
由于它表示导入错误,这里是我的导入:
#/usr/bin/env python3
#import necessary packages
from tkinter import *
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
from PIL import ImageTk, Image
import time
import io
import os
import serial
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from matplotlib import pyplot as plt
import matplotlib.animation as animation
import numpy as np
import sys
import random
此外,这里是.desktop文件。(我确实让脚本可执行)
[Desktop Entry]
Name=GUI DESKTOP
Exec=/home/pi/Desktop/oldtext.py
Icon=/usr/share/pixmaps/idle.xpm
Terminal=false
Type=Application
Categories=Application;Development;
StartupNotify=true
这里发生了什么?我假设这些错误是导致文件在图标点击时不打开的原因。有没有人有线索?
答案 0 :(得分:1)
请注意,在您的错误中,它说:
File "oldtext.py", line 3, in <module>
from tkinter import *
File "/home/pi/Desktop/tkinter.py", line 13, in <module>
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
第二部分File "/home/pi/Desktop/tkinter.py"
是重要的部分。它显示tkinter
模块已被另一个文件覆盖。并且,此文件的第13行是from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
,这也是您在问题中粘贴的代码的第13行。我的猜测是你的文件名为tkinter.py
,你需要重命名它才能使你的脚本工作。