Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
2017-07-20 20:06
1131 查看
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错
2、删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可
"AttributeError: 'module' object has no attribute 'xxx'"。这其实是.pyc文件存在问题。
问题定位:
查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件问题解决方法:
1、命名py脚本时,不要与python预留字,模块名等相同2、删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可
相关文章推荐
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 【Python 脚本报错】AttributeError:'module' has no attribute 'xxx'的解决方法
- 【python学习笔记(2)】脚本报错"AttributeError: 'module' object has no attribute 'xxx'"解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’
- python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute ’urllibopen'(Python 2.7.11 )
- python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
- Django报错: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,原因分析及解决方法