我正在运行python 3.7,我试图创建一个文件,作为我创建的www.example.com的操作符loginpage.py,但当我运行operator.py文件时,它给出了很多错误,但它没有指定问题,指定的一个问题是AttributeError:模块'collections'没有'namedtuple'属性
我试过在一个由pycharm制作的env中运行它,检查了所有可能的语法,一切看起来都很好,我试过在pything 2.2到3.6中运行,但没有工作
from kivy.uix.boxlayout import BoxLayout
class OperatorWindow(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
class OperatorApp(App):
def build(self):
return OperatorWindow()
if __name__ == "__main__":
oa = OperatorApp()
oa.run()
#code ends here
Traceback (most recent call last):
File "D:/OneDrive/Udemy/My own apps/pos/operator/operator.py", line 1, in <module>
from kivy.app import App
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\__init__.py", line 32, in <module>
import shutil
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\shutil.py", line 10, in <module>
import fnmatch
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\fnmatch.py", line 14, in <module>
import re
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 125, in <module>
import functools
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\functools.py", line 21, in <module>
from collections import namedtuple
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\collections\__init__.py", line 21, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
File "D:\OneDrive\Udemy\My own apps\pos\operator\operator.py", line 1, in <module>
from kivy.app import App
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\app.py", line 316, in <module>
from inspect import getfile
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\inspect.py", line 35, in <module>
import dis
File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\dis.py", line 184, in <module>
_Instruction = collections.namedtuple("_Instruction",
AttributeError: module 'collections' has no attribute 'namedtuple'
预期从这是打开一个窗口称为操作员,它将是空白的,但它不会打开它
我用上面的代码把它放进去的错误消息
1条答案
按热度按时间pcww981p1#
将模块命名为
operator
并不是一个好的选择,它会遮蔽标准库中的一个模块。关键的困难是
import operator
现在不会拉入通常的函数。考虑将所有内容向下推一层,这样您就可以使用
myapp.operator
而不是operator
来访问模块。或者,您可以重命名为operator1.py
,或者重命名operator
目录。