Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import pg erroring out in Python3.9

Tags:

python

whenever I use import pg in my code I get following error

>>> import pg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/pg/__init__.py", line 3
    async,
    ^
SyntaxError: invalid syntax

I tried it using pyCharm and terminal directly as well. I am using Python3.9 , import sys; print(sys.version) output

3.9.1 (default, Dec 29 2020, 08:52:17)
[Clang 12.0.0 (clang-1200.0.32.28)]

My objective is to use connect to redshift. However I am able to use pg8000 but what does this error mean? As per documentation online async was added after python 3.3 and since I am using 3.9 it should get imported without error

like image 672
Garvit Arora Avatar asked Sep 15 '25 14:09

Garvit Arora


1 Answers

This is happening because you have a 'pg' package installed that is conflicting with the pg module. You may have installed

pip install pg

instead of

pip install PyGreSQL

library. This async keyword issue is from the former. Assuming you dont need the other pg module, delete the pg directory altogether (in your case from /usr/local/lib/python3.9/site-packages/pg) , install the pygresql using the correct pip command if not done already, and try again. you should not get these issues.

like image 151
Deepak Gaur Avatar answered Sep 18 '25 10:09

Deepak Gaur