Rumah  >  Soal Jawab  >  teks badan

python3.x - python错误:module 'json' has no attribute 'load'

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等。

迷茫迷茫2765 hari yang lalu1775

membalas semua(2)saya akan balas

  • 迷茫

    迷茫2017-04-18 09:36:22

    Atas sebab tertentu, apabila mengimport json, modul terbina dalam python tidak diimport, tetapi fail json.py tempatan anda diimport! !

    Fail "/Users/X/Desktop/crawl_keywords/json.py", baris 12, dalam <module>
    ...
    Fail "/Users/Ru/Desktop/crawl_keywords/ json.py", baris 10, dalam <modul>

    Anda boleh lihat di https://github.com/xuelangZF/... untuk mengetahui tentang mekanisme import pakej

    balas
    0
  • 阿神

    阿神2017-04-18 09:36:22

    Tulis lebih sedikit perkataan, json.loads, bukan muat

    balas
    0
  • Batalbalas