TabError: inconsistent use of tabs and spaces in indentation 查验及解决方法

报错代码

def eccv16(pretrained=True):model = ECCVGenerator()if(pretrained):import torch.utils.model_zoo as model_zoomodel.load_state_dict(torch.load('/home/ps/.cache/torch/hub/checkpoints/colorization_release_v2-9b330a0b.pth', map_location='cpu'))# model.load_state_dict(model_zoo.load_url('https://colorizers.s3.us-east-2.amazonaws.com/colorization_release_v2-9b330a0b.pth',map_location='cpu',check_hash=True))return model

代码来自github上colorization自监督学习仓库,笔者使用的编辑器是VS Code,注释起来的一句是原文,注释上面的一句是笔者自己添加的,报错正是来自这一句:

File "/home/ps/JJ_Projects/ssl_transformer_aes/ssl_related/colorization-master/colorizers/eccv16.py", line 105model.load_state_dict(torch.load('/home/ps/.cache/torch/hub/checkpoints/colorization_release_v2-9b330a0b.pth', map_location='cpu'))^
TabError: inconsistent use of tabs and spaces in indentation

可以看到报错信息大概是说tabspace的缩进不一致,但是我们肉眼明明看到缩进是正常对齐的。笔者猜测报错的原因是,原来代码的作者和笔者修改时的编辑器、缩进方式的设置是不一样的。网上查到的解决方法都是将正常不报错的地方的代码前的缩进复制过来。但是这是为什么呢,我们怎么能在报错之前看到哪一行的缩进有问题呢?

查验及解决方法

笔者想到,如果用一种统一的显示方式是否就能看出缩进方式的不同了,因此想到在命令行中输出打印文件内容。

如何查验

我们在命令行使用cat colorizers/eccv16.py命令来查看文件内容:

果不其然,确实是我们自己写的(即报错)行的缩进和其他行是不一致的,虽然在VS Code编辑器中查看时二者是对齐的。

解决方法

那我们先按照网上的解决方法试一试,即将正常不报错的地方的代码前的缩进复制过来,再cat显示文件:

注意,我们将正常缩进复制过来之后,在编辑器中还是对齐的正常的缩进,在cat的结果中,也是对齐的了,那这样就是正常的代码了。这正是网上流传的这种方法能够解决问题的原因。

TabError- inconsistent use of tabs and spaces in indentation 查验及解决方法相关推荐

  1. Python中出现“TabError: inconsistent use of tabs and spaces in indentation”原因和解决方法

    初学python,很多调试都会出现 "TabError: inconsistent use of tabs and spaces in indentation" 这个错误,看着明显 ...

  2. Python中出现“TabError: inconsistent use of tabs and spaces in indentation”问题的解决

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/82745068 本文出自[我是干勾鱼的博客] 执行Python代码时,如果出现错误 ...

  3. Python 缩进问题-inconsistent use of tabs and spaces in indentation.原因及解决方法

    TabError: inconsistent use of tabs and spaces in indentation 这个问题是说用了制表符做了 python 的缩进. python 的缩进是 4 ...

  4. 成功解决TabError: inconsistent use of tabs and spaces in indentation

    成功解决TabError: inconsistent use of tabs and spaces in indentation 目录 解决问题 解决思路 解决方法 解决问题 TabError: in ...

  5. 【Python】如何解决“TabError: inconsistent use of tabs and spaces in indentation”问题

    python运行代码时,如果出现如下错误: TabError: inconsistent use of tabs and spaces in indentation 很明显,标志是Tab错误,引起这种 ...

  6. TabError: inconsistent use of tabs and spaces in indentation

    Python 编译报错: TabError: inconsistent use of tabs and spaces in indentation 编译环境: python3.5  ,操作系统 Win ...

  7. 让sublime text显示空格,到底是点还是横杠TabError: inconsistent use of tabs and spaces in indentation

    报错情况:TabError: inconsistent use of tabs and spaces in indentation 分析,因为前面点部分从网上复制的,后面横杠是自己写的,这种混合写法会 ...

  8. sublime text下 Python 问题:TabError: inconsistent use of tabs and spaces in indentation

    File "G:\ST\Python\code.py", line 52while left < right and (nums[left] == nums[left+1]) ...

  9. python错误提示“TabError: inconsistent use of tabs and spaces in indentation”

    打印奇数代码如下: 观察了很久但是却找不出问题.后来在网上找到了答案.是空格和制表符混合的问题. 在notepad++中显示制表符的步骤如下: 显示后代码格式如下: 将空格变为制表符后(如下)可以成功 ...

最新文章

  1. 输电线路巡检机器人PPT_超高压输电线路巡检机器人系统
  2. 理解GO CONTEXT机制
  3. SimpleRAR-攻防世界-Misc(图文详解),文件块和子块,图片的隐写二维码
  4. Android通过广播监测Wi-Fi和便携式热点开关状态
  5. mybatis学习(36):动态sql-set
  6. android json 教程 pdf,android用jsonReader来解析json,jsonreaderjson
  7. c语言控制倒车雷达系统,倒车雷达控制系统设计
  8. 论docker中 CMD 与 ENTRYPOINT 的区别
  9. 整理最全的Java笔试题库之问答题篇-国企笔试题库
  10. Android运行原理及运行机制知识汇总
  11. html遮罩层动画制作,教你用Flash遮罩层制作漂亮的文字效果
  12. 电商后台管理系统难点(2)
  13. 参与LABSUniswap IDO送普吉岛酒店公寓
  14. 从零开始 了解C++
  15. 论文阅读 (四):MILIS: Multiple Instance Learning with Instance Selection.
  16. 宝塔一键安装部署tipask登录出现错误:The email must be at least 8 characters怎么回事
  17. ensp路由器启动显示错误40
  18. 舌尖上的中国第一季整理笔记
  19. 复杂网络分析工具及其比较(…
  20. 关于线性回归和逻辑回归一些深入的思考

热门文章

  1. node+express项目链接MySQL数据库(最简单版)
  2. Vue+mui实现图片的本地缓存
  3. python3-pandas 缺失数据的处理
  4. 2017计算机等级考试试题,2017年计算机二级考试练习题及答案
  5. angular7.2构建包如何兼容ie_Python 小技巧:如何实现操作系统兼容性打包?
  6. 算法导论 pdf_学习数据结构和算法最好的书是什么?
  7. python批量合并csv_如何在Python中通过多个列合并两个CSV文件
  8. php中$stu_by,PHP基础案例二:计算学生年龄
  9. php 对象转换成数组,PHP把对象转换为数组的问题
  10. 打印三角形之细节讲解