python AttributeError: 'module' object has no attribute 'dumps'解决办法
2016-09-01 20:28
1136 查看
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError:
'module' object
has no attribute'xxx'"。这其实是.pyc文件存在问题。
问题定位:
查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件
问题解决方法:
1. 命名py脚本时,不要与python预留字,模块名等相同
2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可
'module' object
has no attribute'xxx'"。这其实是.pyc文件存在问题。
问题定位:
查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件
问题解决方法:
1. 命名py脚本时,不要与python预留字,模块名等相同
2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可
相关文章推荐
- AttributeError: 'module' object has no attribute '_base' 可行解决办法
- Python2.7 安装mock出现AttributeError: 'module' object has no attribute的解决方法
- AttributeError: 'module' object has no attribute 'SSL_ST_INIT' 解决办法
- python “AttributeError: '_csv.reader' object has no attribute'next'” 报错的解决办法
- AttributeError: 'module' object has no attribute '_base' 可行解决办法
- python 2.x和3.x关于 'module' object has no attribute 'open'的解决办法
- python 2.x和3.x关于 'module' object has no attribute 'open'的解决办法
- [置顶] AttributeError: 'module' object has no attribute '_base' 可行解决办法
- AttributeError: 'module' object has no attribute 的解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- import json后,报错:AttributeError: 'module' object has no attribute 'dumps,原因分析及解决方法
- AttributeError: 'module' object has no attribute 'Frame' 解决方法
- AttributeError: 'module' object has no attribute 'Spider' 解决了
- AttributeError: 'module' object has no attribute 的解决方法
- 解决方法——AttributeError: 'module' object has no attribute 'VideoWriter_fourcc'
- python AttributeError: 'module' object has no attribute 'setdefaultencoding'
- AttributeError: 'module' object has no attribute '_handlerList' 错误解决方法
- 'module' object has no attribute 'MLPRegressor'问题解决(Python2.7)
- 关于Python的:'module' object has no attribute 'inet_pton'问题解决