Python IDLE,导入XLRD,在调试模式下生成错误:AttributeError:'_ModuleLock'对象没有属性'name' [英] Python IDLE, importing XLRD, error generated in debug mode: AttributeError: '_ModuleLock' object has no attribute 'name'

查看:90
本文介绍了Python IDLE,导入XLRD,在调试模式下生成错误:AttributeError:'_ModuleLock'对象没有属性'name'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python的新手,这是我第一次尝试调试模式.

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

我已经阅读了关于stackoverflow的几乎类似问题的答案,但似乎没有一个能解决这种情况:

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

当我在调试模式下运行此代码时(IDLE,Windows 10):

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

import xlrd

print('Hello World!')

并在 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'**

该错误仅在调试模式下发生.当我替换其他模块(例如 pprint,datetime,sys )时,在调试模式下不会生成任何错误,因此我只能假定是生成错误的xlrd模块.

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.

为什么我要使用像 xlrd 这样的旧模块,而不是 openpxl ?因为我正在使用由最新版本的LibreOffice Calc创建的电子表格,Python立刻通知我我必须使用 xlrd ,并且不再赘述.

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.

推荐答案

这可能是跟踪器问题的重复版本..我最近找到了我认为的答案,但是还没有写补丁.在4/22和4/23的最后3条消息中讨论了一个需要改善情况的简单更改.在/Lib/idlelib/debugger_r.py的第173行中,在dict_item中进行更改

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)

    value = reprlib.repr(value)

并在顶部添加

import reprlib

编辑2021年1月10日:已对 https://bugs.python.org/issue33065 <进行了更改,并将在3.8、3.9和3.10的下一版本中提供.

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.

这篇关于Python IDLE,导入XLRD,在调试模式下生成错误:AttributeError:'_ModuleLock'对象没有属性'name'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆