Python IDLE, importing XLRD, error generated in debug mode: AttributeError: '_ModuleLock' object has no attribute 'name'

我只是一个虾纸丫 提交于 2021-02-11 14:06:26

问题


I'm a newbie to Python and this is the first time I've tried debug mode.

I've read the answers to almost similar questions on stackoverflow but none of them seem to address this situation:

When I run this code in debug mode (IDLE, Windows 10):

import xlrd

print('Hello World!')

and set a break-point on print('Hello World") and try to step through the code, I get the following error lines:

    > **Traceback (most recent call last):   File "D:/data/python/hello_world.py", line 4, in <module>
    >     import xlrd   File "<frozen importlib._bootstrap>", line 988, in _find_and_load   File "<frozen importlib._bootstrap>", line 148, in __enter__   File "<frozen importlib._bootstrap>", line 174, in _get_module_lock   File "<frozen importlib._bootstrap>", line 59, in __init__   File "<frozen importlib._bootstrap>", line 59, in __init__   File
    > "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\bdb.py",
    > line 88, in trace_dispatch
    >     return self.dispatch_line(frame)   File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\bdb.py",
    > line 112, in dispatch_line
    >     self.user_line(frame)   File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\idlelib\debugger.py",
    > line 24, in user_line
    >     self.gui.interaction(message, frame) AttributeError: '_ModuleLock' object has no attribute 'name'**

The error happens only in debug mode. When I substitute other modules such as pprint, datetime, sys there are no errors generated in debug mode, so I can only assume it is the xlrd module which is generating the errors.

Why am I using an old module like xlrd instead of openpxl? Because I'm working with a spreadsheet created by the latest version of LibreOffice Calc, and Python immediately informed me I had to use xlrd and would go no further.


回答1:


I thought I had the answer but evidently not. I imported openpyxl instead of xlrd, into the hello world code. Same error with the break-point on the same line. I was going to say "back to the drawing board", but I think I'll just work on something else. Very disappointing!




回答2:


This is probably a duplicate of this question, but I haven't answered there yet. This also appears to be a duplicate of this two year old tracker issue.. I recently found what I believe to be the answer but have not written a patch yet. There is a simple change needed that improved the situation, discussed in the last 3 messages of 4/22 and 4/23. In /Lib/idlelib/debugger_r.py, line 173, in dict_item, change

    value = repr(value)

to

    value = reprlib.repr(value)

and add at the top

import reprlib

EDIT Jan 10, 2021: Changes have been applied for https://bugs.python.org/issue33065 and will be in next releases of 3.8, 3.9, and 3.10.



来源:https://stackoverflow.com/questions/61310989/python-idle-importing-xlrd-error-generated-in-debug-mode-attributeerror-mo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!