码迷,mamicode.com
首页 > 编程语言 > 详细

python 脚本运行时报错: AttributeError: 'module' object has no attribute ***

时间:2018-01-19 14:03:07      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:情况下   ***   xxx   一个   ref   tee   错误   机器   word   

最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"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   一个   ref   tee   错误   机器   word   

原文地址:https://www.cnblogs.com/xiyuan2016/p/8316084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!