Python to hive connectivity

Is there anyway to connect hive DB from python3.8? I tried in Jupyter using below steps

  1. from pyhive import hive
  2. pip install sasl
  3. conn = hive.Connection(host=host_name, port=8888, username=user,password=password,
    database=database,auth=‘CUSTOM’)

SASL package I am not able to install getting error for newer version of Micrsofot VS 14.0 but as per error message it seems it can be bypassed.

Alternatively can we connect hive using available JDBC connection api.

Please suggest

But getting below error:-
conn = hive.Connection(host=host_name, port=8888, username=user,password=password,
database=database,auth=‘CUSTOM’)

ModuleNotFoundError Traceback (most recent call last)
in
----> 1 conn = hive.Connection(host=host_name, port=8888, username=user,password=password,
2 database=database,auth=‘CUSTOM’)

~\Anaconda3\lib\site-packages\pyhive\hive.py in init(self, host, port, scheme, username, database, auth, configuration, kerberos_service_name, password, check_hostname, ssl_cert, thrift_transport)
201 elif auth in (‘LDAP’, ‘KERBEROS’, ‘NONE’, ‘CUSTOM’):
202 # Defer import so package dependency is optional
→ 203 import sasl
204 import thrift_sasl
205

ModuleNotFoundError: No module named ‘sasl’

You cannot import hive until after installing sasl. You have to do that first:

  • install sasl using pip (you only need to do this once)
  • only after sasl is installed will you be able to import hive.

I am not a Jupyter expert, but I think this should work for you:

  • Start Jupyter as normal.
  • Run these two commands:
import sys
!{sys.executable} -m pip install sasl

Take extra notice of the exclamation mark ! at the start of the second line.

If you get an error from that, please copy and paste the full error in your reply.

Thanks for Reply, It is giving me below error.

building ‘sasl.saslwrapper’ extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: Microsoft C++ Build Tools - Visual Studio
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

Encountered error while trying to install package.

sasl

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Does it mean now I need to install Visual C++ 14?

I am not a Windows or Visual C++ expert, but it sure looks like you need to install MS Visual C++ 14.0 or greater to get that to work.