0

i'm getting AttributeError: partially initialized module 'json' has no attribute 'loads' (most likely due to a circular import), i searched a lot on google an nothing worked. I don't have any module called json or something like that so that's not the problem.

My system is Macos . And i try to run Qgis modules with pycharm. This is the full error:

  File "/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/projs/project.py", line 3, in <module>
    import json
  File "/Applications/QGIS.app/Contents/Resources/python/json/__init__.py", line 106, in <module>
    from .decoder import JSONDecoder, JSONDecodeError
  File "/Applications/QGIS.app/Contents/Resources/python/json/decoder.py", line 5, in <module>
    from json import scanner
  File "/Applications/QGIS.app/Contents/Resources/python/json/scanner.py", line 5, in <module>
    from _json import make_scanner as c_make_scanner
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/psycopg2/_json.py", line 33, in <module>
    from psycopg2._psycopg import ISQLQuote, QuotedString
  File "/Applications/QGIS.app/Contents/Resources/python/site-packages/psycopg2/__init__.py", line 67, in <module>
    from psycopg2 import extensions as _ext
  File "/Applications/QGIS.app/Contents/Resources/python/site-packages/psycopg2/extensions.py", line 192, in <module>
    JSON, JSONARRAY = register_default_json()
  File "/Applications/QGIS.app/Contents/Resources/python/site-packages/psycopg2/_json.py", line 137, in register_default_json
    return register_json(conn_or_curs=conn_or_curs, globally=globally,
  File "/Applications/QGIS.app/Contents/Resources/python/site-packages/psycopg2/_json.py", line 117, in register_json
    JSON, JSONARRAY = _create_json_typecasters(
  File "/Applications/QGIS.app/Contents/Resources/python/site-packages/psycopg2/_json.py", line 157, in _create_json_typecasters
    loads = json.loads
AttributeError: partially initialized module 'json' has no attribute 'loads' (most likely due to a circular import)

Any ideas? I think it psycopg2 thing but couldn't find a solution

Micha
  • 93
  • 1
  • 7
  • Try changing the "from ... import ..." to simply "import ..." – CozyCode Dec 11 '21 at 08:07
  • What is the minimum code you need to cause the problem? Can you give steps to reproduce the problem, starting with installing the libraries on a new system? – Karl Knechtel Dec 11 '21 at 08:42
  • @KarlKnechtel All i did was adding Qgis to the interpreter path and installed things like Psycopg2, Pyqt, config. As you can see in the errors most of the errors come from psycopg2 – Micha Dec 11 '21 at 10:44
  • @CozyCode didn't work, it seems like the errors come from psycopg2 and json not my code directly. All i do in my code is to import json – Micha Dec 11 '21 at 10:46

1 Answers1

0

After looking at my interpreter paths i noticed that i have path that leads to psycopg2 in another version of python.

After deleting the path everything worked.

Preferences -> Python interpreter -> settings icon -> show all -> show paths of selected .. -> delete the path

Micha
  • 93
  • 1
  • 7