Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'psycopg_binary.pq' has no attribute 'PGcancelConn' #68

Open
hanahh080601 opened this issue Jul 1, 2024 · 1 comment

Comments

@hanahh080601
Copy link

Python 3.11

pip list:

Package                                  Version
---------------------------------------- ---------------
aiohttp                                  3.9.5
aiosignal                                1.3.1
alembic                                  1.13.2
annotated-types                          0.7.0
anyio                                    4.4.0
appdirs                                  1.4.4
appnope                                  0.1.4
argon2-cffi                              23.1.0
argon2-cffi-bindings                     21.2.0
arrow                                    1.3.0
asgiref                                  3.8.1
asttokens                                2.4.1
async-lru                                2.0.4
attrs                                    23.2.0
Babel                                    2.15.0
backoff                                  2.2.1
bcrypt                                   4.1.3
beautifulsoup4                           4.12.3
bleach                                   6.1.0
boto3                                    1.34.136
botocore                                 1.34.136
Brotli                                   1.1.0
build                                    1.2.1
cachetools                               5.3.3
certifi                                  2024.6.2
cffi                                     1.16.0
charset-normalizer                       3.3.2
chroma-hnswlib                           0.7.3
chromadb                                 0.4.24
clarifai                                 10.5.3
clarifai-grpc                            10.5.4
click                                    8.1.7
cohere                                   5.5.8
coloredlogs                              15.0.1
comm                                     0.2.2
contextlib2                              21.6.0
crewai                                   0.35.3
crewai-tools                             0.4.1
cryptography                             42.0.8
dataclasses-json                         0.6.7
debugpy                                  1.8.2
decorator                                5.1.1
defusedxml                               0.7.1
Deprecated                               1.2.14
deprecation                              2.1.0
distro                                   1.9.0
dnspython                                2.6.1
docker                                   7.1.0
docstring_parser                         0.16
docx2txt                                 0.8
email_validator                          2.2.0
embedchain                               0.1.113
embedchain-crewai                        0.1.114
executing                                2.0.1
fastapi                                  0.111.0
fastapi-cli                              0.0.4
fastavro                                 1.9.4
fastjsonschema                           2.20.0
filelock                                 3.15.4
flatbuffers                              24.3.25
fqdn                                     1.5.1
frozenlist                               1.4.1
fsspec                                   2024.6.1
gitdb                                    4.0.11
GitPython                                3.1.43
google-api-core                          2.19.1
google-auth                              2.30.0
google-cloud-aiplatform                  1.57.0
google-cloud-bigquery                    3.25.0
google-cloud-core                        2.4.1
google-cloud-resource-manager            1.12.3
google-cloud-storage                     2.17.0
google-crc32c                            1.5.0
google-resumable-media                   2.7.1
googleapis-common-protos                 1.63.2
gptcache                                 0.1.43
grpc-google-iam-v1                       0.13.1
grpcio                                   1.64.1
grpcio-status                            1.62.2
h11                                      0.14.0
httpcore                                 1.0.5
httptools                                0.6.1
httpx                                    0.27.0
httpx-sse                                0.4.0
huggingface-hub                          0.23.4
humanfriendly                            10.0
idna                                     3.7
importlib_metadata                       7.1.0
importlib_resources                      6.4.0
iniconfig                                2.0.0
inquirerpy                               0.3.4
instructor                               1.3.3
ipykernel                                6.29.5
ipython                                  8.26.0
ipywidgets                               8.1.3
isoduration                              20.11.0
jedi                                     0.19.1
Jinja2                                   3.1.4
jiter                                    0.4.2
jmespath                                 1.0.1
json5                                    0.9.25
jsonpatch                                1.33
jsonpointer                              3.0.0
jsonref                                  1.1.0
jsonschema                               4.22.0
jsonschema-specifications                2023.12.1
jupyter                                  1.0.0
jupyter_client                           8.6.2
jupyter-console                          6.6.3
jupyter_core                             5.7.2
jupyter-events                           0.10.0
jupyter-lsp                              2.2.5
jupyter_server                           2.14.1
jupyter_server_terminals                 0.5.3
jupyterlab                               4.2.3
jupyterlab_pygments                      0.3.0
jupyterlab_server                        2.27.2
jupyterlab_widgets                       3.0.11
kubernetes                               30.1.0
lancedb                                  0.5.7
langchain                                0.1.20
langchain-cohere                         0.1.5
langchain-community                      0.0.38
langchain-core                           0.1.52
langchain-openai                         0.1.7
langchain-text-splitters                 0.0.2
langsmith                                0.1.82
Mako                                     1.3.5
markdown-it-py                           3.0.0
MarkupSafe                               2.1.5
marshmallow                              3.21.3
matplotlib-inline                        0.1.7
mdurl                                    0.1.2
mistune                                  3.0.2
mmh3                                     4.1.0
monotonic                                1.6
mpmath                                   1.3.0
multidict                                6.0.5
mutagen                                  1.47.0
mypy-extensions                          1.0.0
nbclient                                 0.10.0
nbconvert                                7.16.4
nbformat                                 5.10.4
nest-asyncio                             1.6.0
nodeenv                                  1.9.1
notebook                                 7.2.1
notebook_shim                            0.2.4
numpy                                    1.26.4
oauthlib                                 3.2.2
onnxruntime                              1.18.1
openai                                   1.35.7
opentelemetry-api                        1.25.0
opentelemetry-exporter-otlp-proto-common 1.25.0
opentelemetry-exporter-otlp-proto-grpc   1.25.0
opentelemetry-exporter-otlp-proto-http   1.25.0
opentelemetry-instrumentation            0.46b0
opentelemetry-instrumentation-asgi       0.46b0
opentelemetry-instrumentation-fastapi    0.46b0
opentelemetry-proto                      1.25.0
opentelemetry-sdk                        1.25.0
opentelemetry-semantic-conventions       0.46b0
opentelemetry-util-http                  0.46b0
orjson                                   3.10.5
outcome                                  1.3.0.post0
overrides                                7.7.0
packaging                                23.2
pandocfilters                            1.5.1
parameterized                            0.9.0
parso                                    0.8.4
pexpect                                  4.9.0
pfzy                                     0.3.4
pillow                                   10.4.0
pip                                      24.1.1
platformdirs                             4.2.2
pluggy                                   1.5.0
posthog                                  3.5.0
prometheus_client                        0.20.0
prompt_toolkit                           3.0.47
proto-plus                               1.24.0
protobuf                                 4.25.3
psutil                                   6.0.0
psycopg                                  3.2.1
psycopg-binary                           3.1.19
psycopg-pool                             3.2.2
ptyprocess                               0.7.0
pulsar-client                            3.5.0
pure-eval                                0.2.2
py                                       1.11.0
pyarrow                                  16.1.0
pyasn1                                   0.6.0
pyasn1_modules                           0.4.0
pycparser                                2.22
pycryptodomex                            3.20.0
pydantic                                 2.7.4
pydantic_core                            2.18.4
PyGithub                                 1.59.1
Pygments                                 2.18.0
PyJWT                                    2.8.0
pylance                                  0.9.18
PyNaCl                                   1.5.0
pypdf                                    4.2.0
PyPika                                   0.48.9
pyproject_hooks                          1.1.0
pyright                                  1.1.369
pysbd                                    0.3.4
PySocks                                  1.7.1
pytest                                   8.2.2
python-dateutil                          2.9.0.post0
python-dotenv                            1.0.1
python-json-logger                       2.0.7
python-multipart                         0.0.9
python-rapidjson                         1.18
pytube                                   15.0.0
PyYAML                                   6.0.1
pyzmq                                    26.0.3
qtconsole                                5.5.2
QtPy                                     2.4.1
ratelimiter                              1.2.0.post0
referencing                              0.35.1
regex                                    2023.12.25
requests                                 2.32.3
requests-oauthlib                        2.0.0
retry                                    0.9.2
rfc3339-validator                        0.1.4
rfc3986-validator                        0.1.1
rich                                     13.7.1
rpds-py                                  0.18.1
rsa                                      4.9
s3transfer                               0.10.2
schema                                   0.7.5
selenium                                 4.22.0
semver                                   3.0.2
Send2Trash                               1.8.3
setuptools                               68.2.0
shapely                                  2.0.4
shellingham                              1.5.4
six                                      1.16.0
smmap                                    5.0.1
sniffio                                  1.3.1
sortedcontainers                         2.4.0
soupsieve                                2.5
SQLAlchemy                               2.0.31
stack-data                               0.6.3
starlette                                0.37.2
sympy                                    1.12.1
tabulate                                 0.9.0
tenacity                                 8.4.2
terminado                                0.18.1
tiktoken                                 0.7.0
tinycss2                                 1.3.0
tokenizers                               0.19.1
tornado                                  6.4.1
tqdm                                     4.66.4
traitlets                                5.14.3
trio                                     0.25.1
trio-websocket                           0.11.1
tritonclient                             2.47.0
typer                                    0.12.3
types-python-dateutil                    2.9.0.20240316
types-requests                           2.32.0.20240622
typing_extensions                        4.12.2
typing-inspect                           0.9.0
ujson                                    5.10.0
uri-template                             1.3.0
urllib3                                  2.2.2
uvicorn                                  0.30.1
uvloop                                   0.19.0
watchfiles                               0.22.0
wcwidth                                  0.2.13
webcolors                                24.6.0
webencodings                             0.5.1
websocket-client                         1.8.0
websockets                               12.0
wheel                                    0.41.2
widgetsnbextension                       4.0.11
wrapt                                    1.16.0
wsproto                                  1.2.0
yarl                                     1.9.4
youtube-transcript-api                   0.6.2
yt-dlp                                   2023.12.30
zipp                                     3.19.2

My code:

from crewai_tools import PGSearchTool

postgresql_tool = PGSearchTool(
    db_uri="postgresql://localhost:password@localhost:5432/database", 
    table_name='users'
)

And it appeared an error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 22
     15 convert_task = Task(
     16   description='Convert the following natural language input into a rule-based command: Chỉ lấy các ứng viên dưới 30 tuổi nếu là nữ, trên 40 tuổi và đã có gia đình nếu là nam. Nhà giàu, ngoại hình ưa nhìn, đang sống ở Đà Nẵng',
     17   agent=rules_creator_agent,  # Assigning the task to the researcher
     18   expected_output='A refined finalized version of the structured format rules which can be used to query the SQL table with JSON data'
     19 )
     21 # Initialize the tool with the database URI and the target table name
---> 22 postgresql_tool = PGSearchTool(
     23     db_uri=os.getenv("POSTGRESQL_URL"), 
     24     table_name='candidates'
     25 )
     27 query_agent = Agent(
     28     role='Database Query Specialist',
     29     goal='Execute SQL queries on the database and return results',
   (...)
     35     tools=[postgresql_tool]
     36 )
     37 query_task = Task(
     38     description="Query the table 'candidates' and retrieve data where 'raw_data' column matches specific criteria",
     39     expected_output="List resume_id of candidates matched criteria",
     40     agent=query_agent
     41 )

File ~/Desktop/cc-ai-poc-openai_fine_tune/venv/lib/python3.11/site-packages/crewai_tools/tools/pg_seach_tool/pg_search_tool.py:26, in PGSearchTool.__init__(self, table_name, **kwargs)
     24 def __init__(self, table_name: str, **kwargs):
     25     super().__init__(**kwargs)
---> 26     self.add(table_name)
     27     self.description = f"A tool that can be used to semantic search a query the {table_name} database table's content."
     28     self._generate_description()

File ~/Desktop/cc-ai-poc-openai_fine_tune/venv/lib/python3.11/site-packages/crewai_tools/tools/pg_seach_tool/pg_search_tool.py:36, in PGSearchTool.add(self, table_name, **kwargs)
     30 def add(
     31     self,
     32     table_name: str,
     33     **kwargs: Any,
     34 ) -> None:
     35     kwargs["data_type"] = "postgres"
---> 36     kwargs["loader"] = PostgresLoader(config=dict(url=self.db_uri))
     37     super().add(f"SELECT * FROM {table_name};", **kwargs)

File ~/Desktop/cc-ai-poc-openai_fine_tune/venv/lib/python3.11/site-packages/embedchain/loaders/postgres.py:18, in PostgresLoader.__init__(self, config)
     16 self.connection = None
     17 self.cursor = None
---> 18 self._setup_loader(config=config)

File ~/Desktop/cc-ai-poc-openai_fine_tune/venv/lib/python3.11/site-packages/embedchain/loaders/postgres.py:22, in PostgresLoader._setup_loader(self, config)
     20 def _setup_loader(self, config: dict[str, Any]):
     21     try:
---> 22         import psycopg
     23     except ImportError as e:
     24         raise ImportError(
     25             "Unable to import required packages. \
     26                 Run `pip install --upgrade 'embedchain[postgres]'`"
     27         ) from e

File ~/Desktop/cc-ai-poc-openai_fine_tune/venv/lib/python3.11/site-packages/psycopg/__init__.py:9
      5 # Copyright (C) 2020 The Psycopg Team
      7 import logging
----> 9 from . import pq  # noqa: F401 import early to stabilize side effects
     10 from . import types
     11 from . import postgres

File ~/Desktop/cc-ai-poc-openai_fine_tune/venv/lib/python3.11/site-packages/psycopg/pq/__init__.py:118
    109         sattempts = "\n".join(f"- {attempt}" for attempt in attempts)
    110         raise ImportError(
    111             f"""\
    112 no pq wrapper available.
    113 Attempts made:
    114 {sattempts}"""
    115         )
--> 118 import_from_libpq()
    120 __all__ = (
    121     "ConnStatus",
    122     "PipelineStatus",
   (...)
    137     "version_pretty",
    138 )

File ~/Desktop/cc-ai-poc-openai_fine_tune/venv/lib/python3.11/site-packages/psycopg/pq/__init__.py:104, in import_from_libpq()
    102     Escaping = module.Escaping
    103     PGcancel = module.PGcancel
--> 104     PGcancelConn = module.PGcancelConn
    105     __build_version__ = module.__build_version__
    106 elif impl:

AttributeError: module 'psycopg_binary.pq' has no attribute 'PGcancelConn'
@hanahh080601
Copy link
Author

I found an alternative way to run this:
pip uninstall psycopg-binary -y
pip install psycopg-c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant