simplejson AttributeError:“模块”对象没有属性“转储”
我是编程新手,我有一个关于以下错误的问题。 我使用的是python 2.7.,我使用以下脚本创建了一个简单的图形示例,该示例取自Eric Matthes的python CrashCourse:simplejson AttributeError:“模块”对象没有属性“转储”,json,matplotlib,simplejson,Json,Matplotlib,Simplejson,我是编程新手,我有一个关于以下错误的问题。 我使用的是python 2.7.,我使用以下脚本创建了一个简单的图形示例,该示例取自Eric Matthes的python CrashCourse: import matplotlib.pyplot as plt squares = [1,4,9,16,25] plt.plot(squares, linewitdth = 5) #Set chart title and lable axes. plt.tit
import matplotlib.pyplot as plt
squares = [1,4,9,16,25]
plt.plot(squares, linewitdth = 5)
#Set chart title and lable axes.
plt.title("Square Numbers", fontsize = 24)
plt.xlabel("Value", fontsize = 14)
plt.ylabel("Square of Value", fontsize = 14)
# Set size of tick labels
plt.tick_params(axis = "both", labelsize = 14)
plt.show()
在WindowsPowerShell中运行此脚本时,出现以下错误:
Traceback (most recent call last): File "mpl_squares.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Users\Roger\Anaconda2\lib\sitepackages\matplotlib\__init__.py, line 134, in <module> from ._version import get_versions
File "C:\Users\Roger\Anaconda2\lib\site-packages\matplotlib\_version.py", line 7, in <module> import json
File "C:\Users\Roger\Desktop\lpthw\json.py", line 7, in <module>
AttributeError: "module" object has no attribute "dump"
问题:
您认为我必须通过替换来修复_version.py模块中的某些内容吗
导入json以导入simplejson和模块中添加的函数
我正在考虑解决这个问题,但我不想修改_version.py中的任何内容,如果它让事情变得更糟的话。非常感谢您的意见和建议
致以最诚挚的问候您的C:\Users\Roger\Desktop\lpthw\json.py似乎被导入,而不是Python的内置模块
您是否以某种方式将文件夹C:\Users\Roger\Desktop\lpthw添加到PYTHONPATH中,例如使用sys.path.append或PYTHONPATH变量?阅读更多关于
simplejson的修复之所以有效,是因为它没有被其他同名模块覆盖
尝试将C:\Users\Roger\Desktop\lpthw\json.py重命名为类似C:\Users\Roger\Desktop\lpthw\myjson.py的名称,并尝试找出lpthw文件夹是如何进入PYTHONPATH的。Wao!非常感谢你!这就是解决办法。我将阅读有关Python如何查找模块的文档,以了解更多信息。谢谢你,我的朋友,在过去的几周里,你帮了我一些让我发疯的事情。祝你有美好的一天!
# This file was generated by 'versioneer.py' (0.15) from
# revision-control system data, or from the parent directory name of an
# unpacked source archive. Distribution tarballs contain a pre-generated
#copy
# of this file.
import json
import sys
version_json = '''
{
"dirty": false,
"error": null,
"full-revisionid": "26382a72ea234ee0efd40543c8ae4a30cffc4f0d",
"version": "1.5.3"
}
''' # END VERSION_JSON
def get_versions():
return json.loads(version_json)