0

I am trying to import parse_dict from by psqlparse:

from psqlparse import parse_dict

Then there is an error below that I cannot seem to find mentioned by anyone on the internet. Does anyone have an idea? Thank you! I am using Python 3.8.5 on Ubuntu 20.04

The error is:

ImportError: cannot import name 'parse_dict' from 'psqlparse' (/home/name/.local/lib/python3.8/site-packages/psqlparse/__init__.py)   
furas
  • 134,197
  • 12
  • 106
  • 148
  • Maybe related to https://stackoverflow.com/a/7508826/3749896 – Sven Eberth May 14 '21 at 21:22
  • i doubt that a psql parser needs to parse a dictionary and doesn't have that function buit maybe this will help https://stackoverflow.com/questions/19248249/how-should-i-parse-a-dict-object – nbk May 14 '21 at 21:25
  • probably there are two different modules `psqlparse` I checked source code on my computer and it doesn't have `parse_dict` but source code [on GitHub](https://github.com/alculquicondor/psqlparse/tree/master/psqlparse) has `parse_dict`. `pip freeze` shows that I have version `0.2.5` but GitHub shows `1.0rc1` (release candidate) – furas May 14 '21 at 22:37
  • you may try `pip install -U psqlparse==1.0rc1` but it seems it has other problems to find other elements – furas May 14 '21 at 22:43
  • Thanks for your inputs! I have tried the solution from the comment below and from @furas and it works – Duc Hoang May 17 '21 at 13:00

1 Answers1

1

It seems there are two versions of psqlparse - default but old 0.2.5 and unofficial (Release Candidate) but the newest 1.0.rc7. Old version doesn't have parse_dict but new one has it.

You can (re)install it with

pip install -U psqlparse==1.0rc7

BTW:

If you try to install wrong version - ie. pip install psqlparse==hello - then it displays error message with all avaliable versions and you can see which version you can install.

furas
  • 134,197
  • 12
  • 106
  • 148