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
等。
어떤 이유에서인지 json을 가져올 때 Python의 내장 모듈을 가져오지 않고 로컬 json.py 파일을 가져옵니다! !
패키지 가져오기 메커니즘에 대해 알아보려면 https://github.com/xuelangZF/...를 살펴보세요
로드하지 않고 json.loads라는 단어를 적게 작성하세요