1

I Installed Hadoop , Pig, Hive, HBase and Zookeeper successfully. I installed Apache Phoenix to access HBase. Below are my PATH variables.

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH="$PATH:$JAVA_HOME/bin"
export PATH="/home/vijee/anaconda3/bin:$PATH"

export HADOOP_HOME=/home/vijee/hadoop-2.7.7
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH="$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin"
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native"

export ZOOKEEPER_HOME=/home/vijee/apache-zookeeper-3.6.2-bin
export PATH=$PATH:$ZOOKEEPER_HOME/bin

export HBASE_HOME=/home/vijee/hbase-1.4.13-bin
export PATH=$PATH:$HBASE_HOME/bin

export PHOENIX_HOME=/home/vijee/apache-phoenix-4.15.0-HBase-1.4-bin
export PATH=$PATH:$PHOENIX_HOME/bin

I copied phoenix-4.15.0-HBase-1.4-client.jar, phoenix-4.15.0-HBase-1.4-server.jar, phoenix-core-4.15.0-HBase-1.4.jar to HBase lib directory and restarted Hbase and Zookeeper. When I run the below Phoenix command, it is throwing error

(base) vijee@vijee-Lenovo-IdeaPad-S510p:~/apache-phoenix-4.15.0-HBase-1.4-bin/bin$ psql.py localhost $PHOENIX_HOME/examples/WEB_STAT.sql $PHOENIX_HOME/examples/WEB_STAT.csv $PHOENIX_HOME/examples/WEB_STAT_QUERIES.sql
Traceback (most recent call last):
  File "/home/vijee/apache-phoenix-4.15.0-HBase-1.4-bin/bin/psql.py", line 57, in <module>
    if hbase_env.has_key('JAVA_HOME'):
AttributeError: 'dict' object has no attribute 'has_key'

My Python Version

$ python --version
Python 3.8.3

I know it is Python compatability issue and psql.py is written for Python 2.x.

How to resolve this issue?

Green
  • 577
  • 3
  • 10
  • 28

2 Answers2

1

Briefly searching, it looks like HBase-1.4 is from 2017, while the latest stable is 2.2.5 .. the release notes imply that it works with Python 3

Consider simply using the newer jar Apache Archive Link for stable files

At least psql.py in the latest Apache Phoenix code does appear to support Python 3 https://github.com/apache/phoenix/blob/master/bin/psql.py so you should be able to get a newer version than you have which will work with it.

This can be seen in the latest commit to it


If you must use 1.4.x, you may be able to run psql.py with Python 2 instead. Most operating systems will accept having them installed in parallel, though it may make some dependency management confusing and it is not a maintainable solution.

ti7
  • 16,375
  • 6
  • 40
  • 68
  • I installed hbase-2.2.6 and apache-phoenix-5.0.0-HBase-2.0 and again throwing the same error. The psql.py is from apache-phoenix/bin directory. The python code inside psql.py and phoenix_utils.py are in Python 2.x format. where as my Python version is 3.8. I am new for HBase and there is no much information in the web about this issue. – Green Nov 26 '20 at 09:27
  • @Green can you simply use Python 2? – ti7 Nov 26 '20 at 19:36
  • I have Python 3.x and my PySpark is running on Python 3.x. I dont know how to use Python 2 only to run Phoenix. – Green Nov 27 '20 at 07:11
  • 1
    If you install python2 (directions will depend on OS .. for Debian derivatives [`apt install python2.7`](https://askubuntu.com/questions/981118/correct-way-to-install-python-2-7-on-ubuntu-17-10)) then you can run with it as `python2 psql.py `. However, there is a lot of effort and the latest version should work with Python 3, so suspecting this I went and checked. The latest version _does_ support it, so I'd encourage you to use that, as it will be much more maintainable (Python 2 support ended at the start of this year and the project is clearly now being developed with Python 3) – ti7 Nov 27 '20 at 16:44
  • 1
    @Green I've edited my answer to include that information, along with a few supporting links! – ti7 Nov 27 '20 at 17:00
  • 1
    Wonderful I succeded thanks...... I made required changes in python script files in Phoenix bin folder as in Git. – Green Nov 27 '20 at 21:29
0

.has_key was removed in 3.x, use in instead!

See also Should I use 'has_key()' or 'in' on Python dicts?

ti7
  • 16,375
  • 6
  • 40
  • 68