最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'moduleobject 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 ***的更多相关文章

  1. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  2. python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'

    python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...

  3. facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' object has no attribute 'iteritems'

    报错原因:在进行facenet进行train_softmax.py训练时,在一轮训练结束进行验证时,报错AttributeError: 'dict' object has no attribute ' ...

  4. zc.buildout构建项目时报错‘AttributeError: '_NamespacePath' object has no attribute 'sort'’

    在使用zc.buildout构建项目时如果碰到‘AttributeError: '_NamespacePath' object has no attribute 'sort'’报错: An inter ...

  5. 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"

    最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...

  6. Python脚本报错AttributeError: 'module' object has no attribute 'maketrans'

    出现此错误的原因:是此文件smtp02.py 所在的目录下有string.pyc 的文件存在,与python库里的string.pyc冲突造成无法确认编译所取的类库.

  7. pycharm install python packaging tools时遇到AttributeError: '_NamespacePath' object has no attribute 'sort'错误

    pycharm install python packaging tools时报错AttributeError: '_NamespacePath' object has no attribute 's ...

  8. AttributeError: 'module' object has no attribute get'

    最近在写python requests相关内容易,突然报错AttributeError: 'module' object has no attribute 'get'" 脚本肯定没问题 怎么 ...

  9. 使用jieba导入引用方法时,报错AttributeError: module 'jieba' has no attribute 'cut'

    一.问题描述 import jieba导入后,使用jieba.cut()方法时报错AttributeError: module 'jieba' has no attribute 'cut' 二.问题分 ...

随机推荐

  1. [心平气和读经典]The TCP/IP Guide(002)

    The TCP/IP Guide [Page 41, 42] Goals of The TCP/IP Guide | 本书的目标 Every author who sets out to write ...

  2. 《高质量c++/c编程指南》学习摘要

    1. 尽可能在定义变量的同时初始化该变量(就近原则)——防止忘记初始化,引用未被初始化的变量,可能导致程序错误 2. 代码行最大长度宜控制在70~80个字符以内(长行拆分)——否则眼睛看不过来,也不便 ...

  3. 《Think Python》第17章学习笔记

    目录 <Think Python>第17章学习笔记 17.1 面向对象的特性(Object-oriented features) 17.2 打印对象(Printing objects) 1 ...

  4. Python DataFrame导出CSV、数据库

    写入Oracle from sqlalchemy import create_engine import pandas as pd import numpy as np df = pd.DataFra ...

  5. 数据库索引--------B/B+树、聚集、非聚集、符合索引

    摘录自博客:http://www.cnblogs.com/morvenhuang/archive/2009/03/30/1425534.html 一.引言 对数据库索引的关注从未淡出我的们的讨论,那么 ...

  6. unity多线程

    多线程概念 多线程,是指实现多个线程并发执行的技术,合理利用多线程可以提升程序的性能,在unity中,一般是避免使用多线程的,unity对多线程的支持并不友好. 协程概念 协程,是指在主线程运行时开启 ...

  7. JavaScript的柯里化函数

    柯里化,或者说部分应用,是一种函数式编程的技术,对于熟悉以传统方式编写 JavaScript 代码的人来说可能会很费解.但如果使用得当,它可以使你的 JavaScript 函数更具可读性. 更具可读性 ...

  8. [转]Android Studio SQLite Database Example

    本文转自:http://instinctcoder.com/android-studio-sqlite-database-example/ BY TAN WOON HOW · PUBLISHED AP ...

  9. protobuf简单测试应用

    protobuf是google推出的一种数据交换协议,比较适合应用于底层服务交互,nodejs提供protobufjs包的实现,下面是一个简单的测试demo: 首先是.proto文件: package ...

  10. 看libevent所遇到的英语生词

    libevent – an event notification library The libevent API (libevent应用程序)provides a mechanism(机制) to ...