python - ImportError:无法从“json”(未知位置)导入名称“loads”
问题描述
Previos 标题是:
AttributeError: module 'json' has no attribute 'loads'
我更改了它,因为它看起来与此类似,但在我提供的链接中,问题似乎是该人有一个名为的文件,该文件json.py
欺骗了导入,以为导入的是本地文件而不是来自的 json标准库。我的问题是我没有任何名为的本地文件json.py
;
我想知道它是否必须做与 PATH 或我的项目结构相关的任何事情。任何建议都可能有所帮助。
错误回溯:
File "D:\Me\IdeaProjects\src\app\repositories\user_repository.py", line 14, in get_user
user = json.loads(file.read())
我在 Windows 10 和 intelliJ ide 中运行代码。
Python版本:3.7.4
尝试了官方文档中的代码:
import json
def as_complex(dct):
if '__complex__' in dct:
return complex(dct['real'], dct['imag'])
return dct
json.loads('{"__complex__": true, "real": 1, "imag": 2}', object_hook=as_complex)
并且也得到了这个错误:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
json.loads('{"__complex__": true, "real": 1, "imag": 2}',object_hook=as_complex)
AttributeError: module 'json' has no attribute 'loads'
当我尝试loads
显式导入时,出现此错误:
ImportError: cannot import name 'loads' from 'json' (unknown location)
解决方案
我在窗口 10 的管理员帐户中安装了 python,并且它以管理员权限安装,但是当我在另一个帐户中使用时,我无法使用这些包,但是在当前帐户中安装 python 确实解决了问题。
推荐阅读
- virtual-machine - 使用 gitlab-ci 创建虚拟机
- javascript - 我想要一种减少重复的方法来重写它
- node.js - 在 MongoDB 中使用 .save() 的问题
- python - 安装 pip-requests 的巨大问题(尚未在所有 SO 中找到帮助)
- python - Flask-Migrate 尝试迁移用户模型抛出错误
- django - 如何在 Django 信号中使用 update_fields
- grafana - Grafana 6.6+ 为 keycloak 用户分配管理员角色
- r - 如何基于组向 geom_split_violin() 添加单个值(形状)?
- php - 在php中单击时添加+1
- javascript - 按顺序处理事件发射器消息