针对AttributeError: ‘module’ object has no attribute’xxx’的错误归类

目前遇见的有三种类型:

  1. 拼写错误,模块一定要拼写错误,这个也是最容易犯的,发现找不到模块的时候,最好先检查一遍自己引入的模块拼写尤其是那些名字非常长的比如HTTPPasswordMgrWithDefaultRealm,这种里有部分字母要大写的一定要注意
  2. 就是在python3中,引入主模块不会将相应的子模块引入,比如引入urllib模块,但是使用的时候用的是urllib.request模块,那么在开头引入的时候就应该写的是import  urllib.request
  3. 定义python文件名的时候,不要手贱去定义一些与python关键词相同的文件名,哪怕你引入的模块不包含,也不要定义,比如引入模块urllib,但是文件名为http,那么他还是会报错,这个方面具体的还可以看下这篇博客http://lovesoo.org/python-script-error-attributeerror-module-object-has-no-attribute-solve-method.html

原文地址:https://www.cnblogs.com/gausstu/p/9490808.html

时间: 2024-08-01 18:47:08

针对AttributeError: ‘module’ object has no attribute’xxx’的错误归类的相关文章

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

最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attribute 'xxx'".这其实是.pyc文件存在问题. 问题定位: 查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件 问题解决方法: 1. 命名py脚本时,不要与python预留字,模块名等相同 2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件

对于AttributeError: ‘module’ object has no attribute ‘AF_INET’ 的错误原因

在python使用import socket后使用socket.AF_INET常量的时候发生在模块中找不到这个常量,很奇怪,在网上查了一下,在python import模块的时候会根据文件的名字进行导入,我的python脚本文件名字恰巧是socket.py,这才导致了导入的socket是错误的,尽量不要让自己的python脚本和模块同名,并且要注意同文件夹下的其他文件名和模块名是否冲突

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文件

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

报错: [[email protected] ~]# ./json.py DATA: [{'a': 'A', 'c': 3.0, 'b': (2, 4)}] Traceback (most recent call last): File "./json.py", line 4, in <module> import json File "/root/json.py", line 8, in <module> data_string = jso

[Python]attributeError:&#39;module&#39; object has no attribute &#39;dump&#39;

[问题] [代码] 文件名:pickle.py # coding=utf-8 #持久存储 import pickle #b 以二进制的模式打开文件 with open('mydata.pickle','wb') as mysavedata: #用dump保存数据 pickle.dump([1,2,'three'],mysavedata) #b 以二进制的模式打开文件 with open('mydata.pickle','rb') as myreaddata: #使用load恢复数据 list =

Faq_flask : AttributeError: ‘module’ object has no attribute ‘autoescape’

原文地址: http://www.suzf.net/thread-0613-153.html 转载须注明原始出处 前些天从 "spider_net" 上找了一篇文章 , 大致就是利用 highcharts + flask + mysql 构建的一个简单的监控系统 ,经过几番挣扎终于还是给捣持出来了 , 现在总结一下 , 分享给大家 .   o_O 部分报错信息: * Detected change in 'flask_web.py', reloading* Restarting wit

service_identity 模块 AttributeError: &#39;module&#39; object has no attribute &#39;Any&#39;

安装scrapy之后,开始第一步创建scrapy的工程,之后提示一个userwarning:提示我service_identity没有安装,我通过pip install service_identity安装之后,重新创建一个scrapy的爬虫工程有提示以下的错误. Traceback (most recent call last): File "/usr/local/bin/scrapy", line 4, in execute() File "/usr/local/lib/

os.uname() AttributeError: &#39;module&#39; object has no attribute &#39;uname&#39;

os.uname() Returns information identifying the current operating system. The return value is an object with five attributes: sysname - operating system name nodename - name of machine on network (implementation-defined) release - operating system rel

AttributeError: &#39;module&#39; object has no attribute &#39;Thread&#39;

$ python thread.py starting at: 2015-08-05 00:24:24Traceback (most recent call last):  File "thread.py", line 28, in <module>    main()  File "thread.py", line 16, in main    th = threading.Thread(target= test,args= (i,2))Attribu