python 脚本运行时报错: AttributeError: 'module' object has no attribute ***
最近在编写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 ***的更多相关文章
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' object has no attribute 'iteritems'
报错原因:在进行facenet进行train_softmax.py训练时,在一轮训练结束进行验证时,报错AttributeError: 'dict' object has no attribute ' ...
- zc.buildout构建项目时报错‘AttributeError: '_NamespacePath' object has no attribute 'sort'’
在使用zc.buildout构建项目时如果碰到‘AttributeError: '_NamespacePath' object has no attribute 'sort'’报错: An inter ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
- Python脚本报错AttributeError: 'module' object has no attribute 'maketrans'
出现此错误的原因:是此文件smtp02.py 所在的目录下有string.pyc 的文件存在,与python库里的string.pyc冲突造成无法确认编译所取的类库.
- pycharm install python packaging tools时遇到AttributeError: '_NamespacePath' object has no attribute 'sort'错误
pycharm install python packaging tools时报错AttributeError: '_NamespacePath' object has no attribute 's ...
- AttributeError: 'module' object has no attribute get'
最近在写python requests相关内容易,突然报错AttributeError: 'module' object has no attribute 'get'" 脚本肯定没问题 怎么 ...
- 使用jieba导入引用方法时,报错AttributeError: module 'jieba' has no attribute 'cut'
一.问题描述 import jieba导入后,使用jieba.cut()方法时报错AttributeError: module 'jieba' has no attribute 'cut' 二.问题分 ...
随机推荐
- JavaScript -- 定义二维数组
方法一:直接定义并且初始化,这种遇到数量少的情况可以用var _TheArray = [["0-1","0-2"],["1-1"," ...
- Java reflect 反射 3 Class.forname
Class.forName("xxx.xx.xx") 1 作用:加载类文件Class.forName(xxx.xx.xx) 返回的是一个类 而非对象 作用就是把对象的模板加载到内存 ...
- 【转】C#微信公众平台开发者模式开启代码
using System; using System.IO; using System.Text; using System.Web.Security; namespace HPZJ.Web.sys. ...
- spring cloud连载第二篇之Spring Cloud Config
Spring Cloud Config Spring Cloud Config为分布式服务提供了服务侧和客户侧的外部配置支持.通过Spring Cloud Config你可以有一个统一的地方来管理所有 ...
- jQueryEasyUI 学习笔记
jQuery EasyUI是什么? jQuery EasyUI是一组基于jQuery的UI插件集合体,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面.开 ...
- 百度开源e-chart初探
前言: 近年来,在数据服务的公司中,数据可视化越来越重要.随着而来的,国内外正在如火如荼的开发各种在线js视图展示框架.而百度的e-chart算是实用性较高且体验最好的!今天闲来无事,便来玩玩~ ec ...
- spring之validation校验
对于任何一个应用而言在客户端做的数据有效性验证都不是安全有效的,这时候就要求我们在开发的时候在服务端也对数据的有效性进行验证.SpringMVC自身对数据在服务端的校验有一个比较好的支持,它能将我们提 ...
- mac下如何找到hosts文件(转)
打开Finder 在菜单中选择[前往][前往文件夹] 或使用快捷键Command+Shift+G 进入跳转路径,输入: /private/etc/ 点击[前往] 即可找到hos ...
- js只允许输入数字和两位小数
一.js只允许输入数字和两位小数 //只允许输入数字和两位小数 function clearNoNum(obj) { obj.value = obj.value.replace(/[^\d.]/g, ...
- spring源码学习(一)
由于本人水平有限,本文内容较为简单,仅供个人学习笔记,或者大家参考,如果能够帮助大家,荣幸之至!本文主要分析AnnotationConfigApplicationContext实例化之后,到底干了那些 ...