AttributeError:'module' xxx.py has no attribute '__path__'

遇到一个局坑爹的bug,实际很简单,但却很难发现到底是哪里出了问题——

Error while finding module specification for 'convert_albert_original_tf_checkpoint_to_pytorch.py' (AttributeError: module 'convert_albert_original_tf_checkpoint_to_pytorch' has no attribute '__path__')

即“AttributeError:'module' xxx.py has no attribute '__path__' ”,其实问题很简单,你去看看你的命令是不是有这个问题:

$ python -m xxx.py

如上面的命令所示,Python -m指的是把这个.py文件当做模块运行,但如果你一不小心加了.py这个后缀,就会出现这个错误。其实你要么把"-m"删除,要么删除".py"后缀,问题就迎刃而解了

  • 13
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在您的问题中,您遇到了一个AttributeError: module 'torchvision.models' has no attribute 'ResNet18_Weights'的错误。这意味着torchvision.models模块中没有名为'ResNet18_Weights'的属性。 要解决这个问题,您可以尝试以下方法之一: 1. 检查torchvision的版本:确保您使用的是最新版本的torchvision。您可以使用pip install torchvision --upgrade命令来更新torchvision到最新版本。 2. 检查模型名称:确保您使用的是正确的模型名称。ResNet18_Weights可能不是torchvision.models中可用的模型之一。您可以查看torchvision.models模块的文档,以确定可用的模型名称。 3. 自定义模型:如果您要使用的模型不是torchvision中提供的预训练模型之一,您可以考虑自定义一个模型。您可以使用torch.nn模块来构建自己的模型。 请注意,在上述解决方法中,第一个方法是最常见的解决方法,确保您使用的是最新版本的torchvision,并查看可用的模型名称。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [AttributeError: module ‘torchvision.models‘ has no attributexxxx‘ 问题和解决](https://blog.csdn.net/Davidietop/article/details/122296013)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [AttributeError: module 'tensorflow.compat.v1' has no attribute '](https://download.csdn.net/download/qq_38766019/86272235)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [AttributeError: module ‘torchvision.models‘ has no attribute ‘regnet_y_400mf](https://blog.csdn.net/weixin_41287060/article/details/129798585)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_illusion_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值