源码片段:

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. USB/GPIO/SDIO

    通用串行总线(英语:Universal Serial Bus,缩写:USB)是连接计算机系统与外部设备的一种串口总线标准,也是一种输入输出接口的技术规范.它只有4根线,两个电源(5V,地线),两个数据 ...

  2. SSM-SpringMVC-10:SpringMVC中PropertiesMethodNameResolver属性方法名称解析器

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 上次的以继承MultiActionController可以实现一个处理器中多个处理方法,但是局限出来了,他们的 ...

  3. Linux时间子系统之四:Timer在用户和内核空间流程

    用户空间应用中创建一个Timer(alarm/setitimer/POSIX Timer等等),然后程序继续执行: 内核进入创建/设置Timer系统调用,开始计时,在超时后通过何种方式通知用户空间: ...

  4. ThinkPHP5+Apicloud+vue商城APP实战

    ThinkPHP5+Apicoud+vue商城APP实战 目录 章节1:项目概述 课时1apicloud平台介绍.04:38 课时2知识体系架构介绍.16:10 章节2:apicloud50分钟快速入 ...

  5. 报错 'dict' object has no attribute 'has_key'

    has_key方法在python2中是可以使用的,在python3中删除了. 比如: if dict.has_key(word): 改为: if word in dict:

  6. Java 读书笔记 (十三) for each 循环

    JDK 1.5引进了一种新的循环类型,被称为foreach循环或者加强型循环,它能在不使用下标的情况下遍历数组. 实例: public class TestArray{ public static v ...

  7. server.go 源码阅读

    ; i < conn.retries(); i++ {         r.conf.addr = conn.addr()         listener, err = net.Listen( ...

  8. Elasticsearch笔记五之java操作es

    Java操作es集群步骤1:配置集群对象信息:2:创建客户端:3:查看集群信息 1:集群名称 默认集群名为elasticsearch,如果集群名称和指定的不一致则在使用节点资源时会报错. 2:嗅探功能 ...

  9. ArrayBlockingQueue简介

    ArrayBlockingQueue基于数组,先进先出,从尾部插入到队列,从头部开始返回. 线程安全的有序阻塞队列,内部通过"互斥锁"保护竞争资源. 指定时间的阻塞读写 容量可限制 ...

  10. 通过jenkins持续集成 github中的代码到 服务器。

    前言 最近自己在探索springboot框架,了解到 jenkins 具有 自动我github 上带项目部署到 tomcat 中.于是决定先搭建一个jenkins 环境在继续研究. Jenkins简介 ...