从代码的角度看Pointer-Generator Networks【上】
-
- 1、ModuleNotFoundError: No module named 'data_util'
- 2、ModuleNotFoundError: No module named 'Queue'
- 3、ModuleNotFoundError: No module named 'config'
- 4、SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Warning: incorrectly formatted line in vocabulary file: %s\n' % line)?
- 5、FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\92458\\ptr_nw/cnn-dailymail-master/finished_files/vocab'
- 6、UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 7012: illegal multibyte sequence
- 7、NameError: name 'xrange' is not defined
- 8、AttributeError: 'generator' object has no attribute 'next'
- 9、TypeError: argument should be integer or bytes-like object, not 'str'
- 10、TypeError: sequence item 0: expected str instance, bytes found
Paper: Get To The Point: Summarization with Pointer-Generator Networks
Code: pointer_summarizer
这篇blog post记录了我把代码跑起来的过程中所遇到的10个BUG。代码原来的环境:Python2.7 +Pytorch0.4,我的环境:Python3.7+Pytorch1.7。
如果您有一些问题,欢迎评论~
1、ModuleNotFoundError: No module named ‘data_util’

报错信息:模块未被发现错误:没有‘data_util’模块
解决过程:
先定位到脚本中出错的位置from data_util import config,再看这个Project的目录,发现data_util存在,只是在这个脚本下找不到它。
观察data_util是在model.py脚本所在文件夹training_ptr_gen的同一目录下,猜测应该是找不到data_util所在路径,所以在当前脚本下将data_util所在路径加入到可搜索的路径列表里,加入的方式如下:
import os
base_dir = os.path.dirname(__file__) #获取当前脚本所在路径
import sys
sys.path.append(os.path.join(base_dir,'../'))

这篇博客详细记录了将Pointer-Generator Networks的代码从Python2迁移到Python3过程中遇到的10个错误及解决方案。包括ModuleNotFoundError(如data_util、Queue、config),SyntaxError(print函数括号缺失),FileNotFoundError(路径问题),UnicodeDecodeError(编码格式问题),NameError(xrange未定义),AttributeError(generator的next方法),以及TypeError(与str和bytes类型相关的错误)。每个错误都给出了具体的解决办法,涉及路径添加、模块名更改、语法调整和类型转换等。
最低0.47元/天 解锁文章
3万+





