首页 > 解决方案 > 为什么 Pycharm 在调试程序时显示 AttributeError: module 'numbers' has no attribute 'Number',但运行时却没有发生错误?

问题描述

Traceback (most recent call last):
  File "E:\Program Files\JetBrains\PyCharm 2019.1\helpers\pydev\pydevd.py", line 15, in <module>
    from _pydevd_bundle.pydevd_constants import IS_JYTH_LESS25, IS_PY34_OR_GREATER, IS_PY36_OR_GREATER, IS_PYCHARM, get_thread_id, \
  File "E:\Program Files\JetBrains\PyCharm 2019.1\helpers\pydev\_pydevd_bundle\pydevd_constants.py", line 169, in <module>
    from _pydev_imps._pydev_saved_modules import thread
  File "E:\Program Files\JetBrains\PyCharm 2019.1\helpers\pydev\_pydev_imps\_pydev_saved_modules.py", line 21, in <module>
    import xmlrpc.client as xmlrpclib
  File "C:\Users\A\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 135, in <module>
    from decimal import Decimal
  File "C:\Users\A\AppData\Local\Programs\Python\Python37\lib\decimal.py", line 3, in <module>
    from _decimal import *
AttributeError: module 'numbers' has no attribute 'Number'

标签: pythonpycharm

解决方案


如果您有相同的模块名称“编号”,请检查您的项目目录,因为 python 标准库还包含一个具有该名称的模块。

所以改变你的模块名称,或者你可以试试这个:

1> Go to Run/Edit/Debug Configurations 
2> For the current file, From the 'Configuration', 'Logs' Tab, Select Configuration Tab (Default)
3> Uncheck both 'Add content to PYTHONPATH' and 'Add source to PYTHONPATH' 

推荐阅读