cannot import name 'sql' from 'databricks'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 08:31 AM
I am working on Databricks version 10.4 premium cluster and while importing sql from databricks module I am getting below error.
cannot import name 'sql' from 'databricks' (/databricks/python/lib/python3.8/site-packages/databricks/__init__.py).Trying to execute below sample code
from databricks import sql
import os
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 * FROM default.x LIMIT 2")
result = cursor.fetchall()
for row in result:
print(row)
ANy suggestion here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 09:05 AM
@Ritu Kumari ignore my last response lol Looks like you need to install this lib:
https://docs.databricks.com/dev-tools/python-sql-connector.html#package
databricks-sql-connector
Usage:
pip install databricks-sql-connector
See also databricks-sql-connector in the Python Package Index (PyPI).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 09:50 AM
Just use natively spark.sql this way code is much faster and simpler you use the power of RDD. All you need is
spark.sql("SELECT * FROM default.x LIMIT 2")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2022 10:28 PM
Hi @Ritu Kumari
Hope all is well!
Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help.
We'd love to hear from you.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2022 04:08 AM
Just currios, why did you use spark.sql for your case I think it easy than import sql from databricks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2022 11:05 PM
I basically used pyodbc
Spark sql is also way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 03:59 AM
There are 2 instances I got this error -
- Installing correct python package. Make sure you install "databricks.sql" module, not "databricks" module. Run below code in jupyter -
%pip install databricks.sql
2. The hostname, os.getenv("DATABRICKS_SERVER_HOSTNAME") returns, should NOT contain "https://".
Please upvote the answer if it solves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:31 PM
I resolve the same error installing library from cluster interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 10:18 PM
if you ever received this kind of error after installing the correct Python package then try running the below command.