简体   繁体   English

为什么PyCharm不能在调试模式下显示PyTorch模块object属性

[英]Why can't PyCharm show PyTorch Module object attributes in debug mode

I define a sub-class of PyTorch's Module in PyCharm and create an instance a :我在 PyCharm 中定义了 PyTorch Module的子类并创建了一个实例a

from torch.nn import Module

class AModule(Module):
    def __init__(self):
        self.something = 10

    def __repr__(self):
        return "AModule"

a = AModule()

If I run the debugger and examine a , I can't see its attributes:如果我运行调试器并检查a ,我看不到它的属性:

在此处输入图像描述

I checked and Module is written in Python (as opposed to being implemented in C), so why is that?我检查了一下, Module是用 Python 编写的(而不是用 C 实现),那是为什么呢?

This is caused by not having properly initialized Module with a super call in the first like of __init__ :这是由于在super之类的第一个调用中没有正确初始化Module __init__的:

super(AModule, self).__init__()

However, PyCharm could have shown more useful information, so I created this issue .然而,PyCharm 可以显示更多有用的信息,所以我创建了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在PyCharm 5.0中调试Python脚本:AttributeError:“模块”对象没有属性“ default_getpass” - Can't debug Python script in PyCharm 5.0: `AttributeError: 'module' object has no attribute 'default_getpass'` 无法在 Pycharm 中调试单元测试 - Can't debug unittests in Pycharm 为什么Pycharm可以找到我的模块,但是无法运行它? - Why Pycharm can find my module,but can't run it? pycharm不会显示对象的所有属性和方法 - pycharm does not show all attributes and methods of a object 为什么我不能在 PyCharm 中安装模块 'pyof'? - Why can't I install the module 'pyof' in PyCharm? 使用Python 3的PyCharm调试模式 - PyCharm debug mode with Python 3 为什么pycharm找不到这个属性和方法参考? - Why pycharm can not find this attributes and methods reference? 我怎样才能拥有不是模块属性的 PyTorch 模块的子模块 - How can I have submodules of a PyTorch Module that are not attributes of the module Intellij / Pycharm无法调试Python模块 - Intellij/Pycharm can't debug Python modules 为什么 Pycharm 在调试程序时显示 AttributeError: module 'numbers' has no attribute 'Number',但运行它却没有发生错误? - Why does the Pycharm show AttributeError: module 'numbers' has no attribute 'Number' when I debug a program, but no error happened if I run it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM