-2

Previos title was: AttributeError: module 'json' has no attribute 'loads' I changed it because it looks similar to this but at the link that i provided, the problem seems that the person was having a file called json.py that was tricking the import to think that is importing a local file and not the json from standard library. My problem is that I don't have any local file called json.py;

I am wondering if it has to do anything related to PATH or the structure of my project. Any suggestion might help.

error traceback:

  File "D:\Me\IdeaProjects\src\app\repositories\user_repository.py", line 14, in get_user
    user = json.loads(file.read())

I am running the code in Windows 10, and intelliJ ide.

Python version: 3.7.4

Tried the code from the official documentation this:

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)

And got this error as well:

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'

When I try to import loads explicitly i get this error:

ImportError: cannot import name 'loads' from 'json' (unknown location)
Sachihiro
  • 1,597
  • 2
  • 20
  • 46

2 Answers2

2

I had python installed in Admin account in window 10 and it was installed with Admin privileges, but when i used in another account I could not use the packages, however installing the python in the current account did fix the problem.

Sachihiro
  • 1,597
  • 2
  • 20
  • 46
0

Try to import loads explicitly:

import json
from json import loads
bimarian
  • 130
  • 1
  • 11