module object has no attribute dumps的解决方法

问题产生原因:

  • python的版本过低,其中的json包年久失修,需要更新

解决方法:

  1. 删除就的json包
>>> import json                                        
>>> print json.__file__                                                      
/home/areynolds/opt/lib/python2.5/site-packages/json.pyc
rm 上面的文件

如果是2.7直接删除完json目录

2.重新安装simplejson

wget https://pypi.python.org/packages/08/48/c97b668d6da7d7bebe7ea1817a6f76394b0ec959cb04214ca833c34359df/simplejson-3.11.1.tar.gz#md5=6e2f1bd5fb0a926facf5d89d217a7183
tar -zxvf simplejson-3.11.1.tar.gz
cd  simplejson-3.11.1
pyhon setup.py install

  • 测试
[root@ice02 simplejson-3.11.1]# python
Python 2.7.2 (default, May  8 2017, 13:21:47) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import simplejson as json
>>> a = {"yu":"so"}
>>> a1 = json.dumps(a) 
>>> print a1
{"yu": "so"}
>>> print type(a1)    
<type 'str'>

posted on 2017-09-01 10:53  小闪电  阅读(1534)  评论(0编辑  收藏  举报

导航