Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

python - ImportError: cannot import name 'loads' from 'json' (unknown location)

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:MeIdeaProjectssrcapp
epositoriesuser_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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...