【Python 脚本报错】AttributeError:'module' has no attribute 'xxx'的解决方法
来源:互联网 发布:景甜面相分析知乎 编辑:程序博客网 时间:2024/05/22 07:40
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本正常的,但执行报错"AttributeError: 'module' object has no attribute 'xxx'",其实是.pyc文件存在问题。
问题定位:查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件
问题解决方法:删除该库的.pyc文件,重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可
示例:
如下Python代码,执行时报错"AttributeError: 'module'object has no attribute 'urlopen'",更新Python27\Lib\urllib2.pyc文件后,即可正常运行。
1
import urllib2
2
url = "http://www.baidu.com"
3
f = urllib2.urlopen(url, timeout=5).read()
4
print len(f)
附录:
pyc文件介绍
pyc文件,是python编译后的字节码(bytecode)文件。只要你运行了py文件,python编译器就会自动生成一个对应的pyc字节码文件。这个pyc字节码文件,经过python解释器,会生成机器码运行(这也是为什么pyc文件可以跨平台部署,类似于java的跨平台,java中JVM运行的字节码文件)。下次调用直接调用pyc,而不调用py文件。直到你这个py文件有改变。python解释器会检查pyc文件中的生成时间,对比py文件的修改时间,如果py更新,那么就生成新的pyc。
0 0
- 【Python 脚本报错】AttributeError:'module' 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学习笔记(2)】脚本报错"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’get’解决方法
- python 报错 **AttributeError: module 'string' has no attribute 'letters'** 的解决方法。
- Python脚本报错AttributeError: ‘module’ object has no attribute ’urllibopen'(Python 2.7.11 )
- C语言基础语法
- 就拿胖子说事
- iOS----------SDWebimage源码解析(5)
- iOS UI 页面的跳转方法
- mac 下命令行编译eclipse 工程
- 【Python 脚本报错】AttributeError:'module' has no attribute 'xxx'的解决方法
- Saudi Arabia
- 上机报告2
- gstreamer AV sync
- CodeForces 651A:Joysticks【模拟】
- 程序员的机器学习入门笔记(二):Python常用库的介绍,及安装(Centos 6.5)
- Linux:Unable to locate package错误解决
- HDOJ--1220--Cube
- erlang趣事六erlangshell ssh登陆