python3.6脚本import json模块后,报错:AttributeError: module 'json' has no attribute 'dumps'
2017-02-16 15:41
1296 查看
编写Python3.6代码,import json模块后,有以下报错:AttributeError: module ‘json’ has no attribute ‘dumps’,报错信息为:模块没有方法dumps
如下图所示:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201910/11/6e43b8ec6fad6ab70292a4deb07f4fc3)
1.查看json模块的方法
![](https://oscdn.geek-share.com/Uploads/Images/Content/201910/11/0aee0ceec6e5105c497149305757d3dd)
2.查看json模块的使用
![](https://oscdn.geek-share.com/Uploads/Images/Content/201910/11/0c4da3d721afa342f0a7fa14f582d1b6)
由上图可知,init.py路径并不是python库下的,因此没有dumps的方法。
3.查看环境变量
首先查询当前目录,然后搜索不到,接着查询,最后查找到F:\python\lib\site-packages
![](https://oscdn.geek-share.com/Uploads/Images/Content/201910/11/ff08cc05e54f9800f6677174790ae025)
查看目录E:\AI\python\lesson_05_文件访问与函数式编程入门\4序列化和反序列化,果真有json.py,和python 库中的json.py冲突。将原脚本json.py改名为json_xulie.py,再运行上述脚本就OK 了。
4.总结报错原因
除F:\python\lib\site-packages外,存在其他目录下存在json.py,import json后,调用json的很多方法就报错。
如下图所示:
1.查看json模块的方法
# dir(json)
2.查看json模块的使用
# help(json)
由上图可知,init.py路径并不是python库下的,因此没有dumps的方法。
3.查看环境变量
首先查询当前目录,然后搜索不到,接着查询,最后查找到F:\python\lib\site-packages
查看目录E:\AI\python\lesson_05_文件访问与函数式编程入门\4序列化和反序列化,果真有json.py,和python 库中的json.py冲突。将原脚本json.py改名为json_xulie.py,再运行上述脚本就OK 了。
4.总结报错原因
除F:\python\lib\site-packages外,存在其他目录下存在json.py,import json后,调用json的很多方法就报错。
相关文章推荐
- import json后,报错:AttributeError: 'module' object has no attribute 'dumps,原因分析及解决方法
- import json后,报错:AttributeError: 'module' object has no attribute 'dumps,原因分析及解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’
- Python脚本报错AttributeError: ‘module’ object has no attribute ’urllibopen'(Python 2.7.11 )
- python 错误解析 AttributeError: 'module' object has no attribute 'dumps'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 学习Python csv模块遇到AttributeError: module 'csv' has no attribute 'writer'和写入后出现空格问题
- 【Python 脚本报错】AttributeError:'module' has no attribute 'xxx'的解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- python 中出现的AttributeError: 'module' object has no attribute '_handlerList'
- AttributeError: 'module' object has no attribute 'handlers'--Python子模块导入问题