源码片段:

class myThread(threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter

执行时提示如下错误:

Traceback (most recent call last):

File "threading.py", line 2, in <module>

import threading

File "I:\MY_TEST\py\thread\threading.py", line 7, in <module>

class myThread(threading.Thread):

AttributeError: 'module' object has no attribute 'Thread'

1、检查是否为threading和Thread拼写错误,认真对比后确认无误;
2、判断是否为threading模块没有安装,查询发现python3.4自带就有此模块;
3、最后检查脚本的名称是threading.py,怀疑是与模块名称冲突,导致加载错误,将脚本名称改为thread_ing.py后执行,正确


由此引出两个问题:

1、命名问题:不管是变量还是脚本名称,都不要和python本身的模块、关键字等重合;

2、Python加载模块顺序问题:

加载模块搜索路径被存储在sys模块中的path变量中,我们使用sys.path输出:

第一个参数是‘’(空串),代表是当前目录,后续的目录分别为PYTHONPATH目录和标准库目录,所以得到加载模块的顺序为:

1)当前主目录

2)PYTHONPATH目录

3)标准库目录

'module' object has no attribute 'Thread'解决方法及模块加载顺序的更多相关文章

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

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

  2. 提示AttributeError: 'module' object has no attribute 'HTTPSHandler'解决方法

    今天在新机器上安装sqlmap,运行提示AttributeError: 'module' object has no attribute 'HTTPSHandler' 网上找了找资料,发现一篇文章ht ...

  3. Python基础学习-'module' object has no attribute 'urlopen'解决方法

    import numpy as npimport urlliburl = "http://archive.ics.uci.edu/ml/machine-learning-databases/ ...

  4. python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?

    python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...

  5. AttributeError: 'module' object has no attribute 'Thread'

    $ python thread.py starting at: 2015-08-05 00:24:24Traceback (most recent call last):  File "th ...

  6. 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法

    pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...

  7. [开发技巧]·AttributeError: module 'pywt' has no attribute 'wavedec'解决方法

    [开发技巧]·AttributeError: module 'pywt' has no attribute 'wavedec'解决方法 1.卸载 pywt pip uninstall pywt 2.安 ...

  8. pygame模块使用时出现AttributeError: module ‘pygame’ has no attribute '…'错误解决方法

    pygame模块使用时出现AttributeError: module 'pygame' has no attribute '-'错误解决方法 首先在pygame中存在init()模块,出现这样的问题 ...

  9. 如何解决requireJs的模块加载超时

    requireJs的加载是一种异步机制,它加载js的时候有个默认的超时机制,当加载一个js超过一定时间的时候,它就会在浏览器中抛出模块加载超时错误,接下来,就不会加载这个模块. 这个机制其实是起到了节 ...

随机推荐

  1. zabbix监控mysql性能

    使用zabbix监控mysql的三种方式 1.只是安装agent 2.启用模板监控 3.启用自定义脚本的模板监控 zabbix中默认有mysql的监控模板.默认已经在zabbix2.2及以上的版本中. ...

  2. mac下nginx安装

    一.安装 Nginx 终端执行: brew search nginx brew install nginx 当前版本 1.10.2,通过brew可以把nginx需要的pcre,openssl,zlib ...

  3. 转:visualvm监控远程机器上的Java程序

    转自:http://hanwangkun.iteye.com/blog/1195526 JDK里面本身就带了很多的监控工具,如JConsole等.我们今天要讲的这款工具visualvm,就是其中的一款 ...

  4. (二)Linux下的crontab定时执行任务命令详解

    在LINUX中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep cron].cron读取一个或多个配置文件,这些配置文件中包含了命令行及其调用时间.cron的配置文件称为&qu ...

  5. 了解mysqlpump工具

    Ⅰ.功能分析 1.1 多线程介绍 mysqlpump是MySQL5.7的官方工具,用于取代mysqldump,其参数与mysqldump基本一样 mysqlpump是多线程备份,但只能到表级别,单表备 ...

  6. DCOS实践分享(4):如何基于DC/OS整合SMACK(Spark, Mesos, Akka, Cassandra, Kafka)

    这篇文章入选CSDN极客头条 http://geek.csdn.net/news/detail/71572 当前,要保证业务的市场竞争力,仅靠设计一个可用并且好看的产品,已经完全不能满足要求.全球消费 ...

  7. Hibernate验证器

    第 4 章 Hibernate验证器  http://hibernate.org/validator/documentation/getting-started/#applying-constrain ...

  8. Spring Boot 使用 Log4j2

    Java 中比较常用的日志工具类,有 Log4j.SLF4j.Commons-logging(简称jcl).Logback.Log4j2(Log4j 升级版).Jdk Logging. Spring ...

  9. Jquery样式

    css样式只有一个的时候: $(function(){ $('p').css('background-color','green'); }) css样式有多个的时候: $(function(){ $( ...

  10. canvas绘制形状

    栅格 之前简单模板中有个宽/高150px的canvas元素.如下图所示,canvas元素默认被网格所覆盖.通常来说网格中的一个单元相当于canvas元素中的一像素.栅格的起点为左上角(坐标为(0,0) ...