'module' object has no attribute 'Thread'解决方法及模块加载顺序
源码片段:
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'解决方法及模块加载顺序的更多相关文章
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- 提示AttributeError: 'module' object has no attribute 'HTTPSHandler'解决方法
今天在新机器上安装sqlmap,运行提示AttributeError: 'module' object has no attribute 'HTTPSHandler' 网上找了找资料,发现一篇文章ht ...
- Python基础学习-'module' object has no attribute 'urlopen'解决方法
import numpy as npimport urlliburl = "http://archive.ics.uci.edu/ml/machine-learning-databases/ ...
- python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?
python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...
- AttributeError: 'module' object has no attribute 'Thread'
$ python thread.py starting at: 2015-08-05 00:24:24Traceback (most recent call last): File "th ...
- 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法
pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...
- [开发技巧]·AttributeError: module 'pywt' has no attribute 'wavedec'解决方法
[开发技巧]·AttributeError: module 'pywt' has no attribute 'wavedec'解决方法 1.卸载 pywt pip uninstall pywt 2.安 ...
- pygame模块使用时出现AttributeError: module ‘pygame’ has no attribute '…'错误解决方法
pygame模块使用时出现AttributeError: module 'pygame' has no attribute '-'错误解决方法 首先在pygame中存在init()模块,出现这样的问题 ...
- 如何解决requireJs的模块加载超时
requireJs的加载是一种异步机制,它加载js的时候有个默认的超时机制,当加载一个js超过一定时间的时候,它就会在浏览器中抛出模块加载超时错误,接下来,就不会加载这个模块. 这个机制其实是起到了节 ...
随机推荐
- HTTP和SOAP完全就是两个不同的协议
HTTP只负责把数据传送过去,不会管这个数据是XML.HTML.图片.文本文件或者别的什么.而SOAP协议则定义了怎么把一个对象变成XML文本,在远程如何调用等,怎么能够混为一谈. ...
- 【一通百通】Bash的单双括号建议:多用[[]], 少用[]
一. bash [ ] 单双括号 基本要素: Ø [ ] 两个符号左右都要有空格分隔 Ø 内部操作符与操作变量之间要有空格:如 [ “a” = “b” ] Ø 字符串比较中,> ...
- elasticsearch x-pack
elasticsearch-plugin.bat install x-pack D:\elasticsearch-5.5.3\bin>elasticsearch-plugin.bat insta ...
- python:解析js中常见的 不带引号的key的 json
首先要明晰一点,json标准中,key是必须要带引号的,所以标准json模块解析不带引号的key的 json就会抛错 不过有一些lib可以帮我们解析 如:demjson(链接) >>> ...
- 某校高中生利用Python,巧妙获取考试成绩,看到成绩后无言以对!
Python是非常有吸引力的编程语言,学习Python的不是帅哥就是美女.为什么这么说呢?因为我和我的女朋友都是学习Python认识的,小编肯定是帅哥,不用去怀疑,而且我眼光特高. 给大伙讲一个故事, ...
- eclipse下搭建hibernate5.0环境
hibernate引入的jar包:hibernate-release-5.0.12.Final.zip 数据库驱动:mysql-connector-java-5.1.46 二.安装hibernate插 ...
- vue 实践记录
打包后使用相对路径 在 build/webpack.prod.conf.js 的 output 节点添加配置:publicPath: './' 打包时使用shell复制文件 在入口 build/bui ...
- etcd_selector.go
) % s.len //not use lock for performance so it is not precise even server := s.Servers[s.cur ...
- search_response.go
package; iScore < utils.MinInt(len(docs[i].Scores), len(docs[j].Scores)); iScore++ { if d ...
- BZOJ_2743_[HEOI2012]采花_离线+树状数组
BZOJ_2743_[HEOI2012]采花_离线+树状数组 Description 萧芸斓是Z国的公主,平时的一大爱好是采花.今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花 .花园足够大 ...