python3.x - python错误:module 'json' has no attribute 'load'
迷茫
迷茫 2017-04-18 09:34:22
0
2
1777

Macbook 今早唤醒,执行下面的几行简单的代码,报错找不到load方法。

import json

# add json data into db
json_path = '/Users/X/Desktop/keywords/ieee_keywords.json'

with open(json_path) as f:
    data =json.load(f)
print(data)
Traceback (most recent call last):
  File "json.py", line 2, in <module>
    import json
  File "/Users/X/Desktop/crawl_keywords/json.py", line 12, in <module>
    data =json.load(f)
AttributeError: module 'json' has no attribute 'load'

这是咋回事,我又尝试新建了一个文件夹,用virtualenv开个虚拟环境,还是这个错误。

甚至我在虚拟环境里试图使用pip install flask

Traceback (most recent call last):
  File "/Users/Ru/Desktop/crawl_keywords/py3/bin/pip", line 7, in <module>
    from pip import main
  File "/Users/Ru/Desktop/crawl_keywords/py3/lib/python3.5/site-packages/pip/__init__.py", line 16, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/Users/Ru/Desktop/crawl_keywords/py3/lib/python3.5/site-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/Users/Ru/Desktop/crawl_keywords/py3/lib/python3.5/site-packages/pip/download.py", line 6, in <module>
    import json
  File "/Users/Ru/Desktop/crawl_keywords/json.py", line 10, in <module>
    data =json.load(f)
AttributeError: module 'json' has no attribute 'load'

其他包同样的,例如psycopg2找不到connect等。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
迷茫

For some reason, when importing json, the built-in module of python is not imported, but your local json.py file is imported! !

File "/Users/X/Desktop/crawl_keywords/json.py", line 12, in <module>
...
File "/Users/Ru/Desktop/crawl_keywords/json.py", line 10, in <module>

You can take a look at https://github.com/xuelangZF/... to learn about the package import mechanism

阿神

There are fewer words, json.loads, not load

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template