Skip to content

[Error] numpy: cannot import name 'Connection' from partially initialized module 'databricks.sql.client' #25

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

Closed
apoclyps opened this issue Aug 1, 2022 · 1 comment

Comments

@apoclyps
Copy link

apoclyps commented Aug 1, 2022

Issue

Attempting to follow the example from the Databricks SQL Connector for Python guide
produces a circular import error.

Traceback (most recent call last):
  File "/Users/apoclyps/workspace/src/select.py", line 4, in <module>
    with sql.connect(
  File "/Users/apoclyps/.pyenv/versions/3.10.3/lib/python3.10/site-packages/databricks/sql/__init__.py", line 47, in connect
    from .client import Connection
  File "/Users/apoclyps/.pyenv/versions/3.10.3/lib/python3.10/site-packages/databricks/sql/client.py", line 8, in <module>
    import pandas
  File "/Users/apoclyps/.pyenv/versions/3.10.3/lib/python3.10/site-packages/pandas/__init__.py", line 16, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
numpy: cannot import name 'Connection' from partially initialized module 'databricks.sql.client' (most likely due to a circular import) (/Users/apoclyps/.pyenv/versions/3.10.3/lib/python3.10/site-packages/databricks/sql/client.py)

Steps to Reproduce

pip install databricks-sql-connector==2.0.2

export DATABRICKS_SERVER_HOSTNAME="https://<redacted>.cloud.databricks.com"
export DATABRICKS_HTTP_PATH="sql/protocolv1/o/<redacted>/<redacted>"
export DATABRICKS_TOKEN="dapi<redacted>"

python main.py

contents of main.py:

import os

from databricks import sql

with sql.connect(
    server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
    http_path=os.getenv("DATABRICKS_HTTP_PATH"),
    access_token=os.getenv("DATABRICKS_TOKEN"),
) as connection:

    with connection.cursor() as cursor:
        cursor.execute("SELECT 1")
        result = cursor.fetchall()

        for row in result:
            print(row)

Additional Information

I believe the issue is caused by the following * import causing a circular import between databricks.sql and databricks.sql.client in databricks/sql/client.py

@susodapop
Copy link
Contributor

susodapop commented Aug 1, 2022

Thanks for opening this issue. It's not a circular import. Our connector depends on numpy which only added support for Python 3.10 on 22 June 22 in version 1.23.0. But we’re pinned to 1.21.1. I've created #26 to track the effort to implement support for Python 3.10.

For now the only mitigation is to use Python 3.7 - 3.9.

[edit] I'm closing this issue in favour of #26.

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

2 participants