I am getting start with Apache AGE python driver and learning about it, at the current time I am exploring the samples that was provided on GitHub so I have decided to go on with an online jupyter platform to test on [google-colab] is the selected one, I have followed the installation guide so that at the beginning of my notebook I have installed the driver using the following commands inside my runtime:
!sudo apt-get update
!sudo apt-get install python3-dev libpq-dev
!git clone https://github.com/apache/age.git
!cd age/drivers/python && pip3 install -r requirements.txt && python3 setup.py install
That gets successfully installed but whenever I try to use it
# Not working
import age
import unittest
from decimal import Decimal
resultHandler = age.newResultHandler()
def evalExp(exp):
value = resultHandler.parse(exp)
print(type(value), "|", exp, " --> " ,value )
mapStr = '{"name": "Smith", "num":123, "yn":true, "bigInt":123456789123456789123456789123456789::numeric}'
evalExp(mapStr)
Output (all methods outputs the same that the module has no attribute)
AttributeError Traceback (most recent call last)
<ipython-input-38-053b6cdde8b8> in <cell line: 6>()
4 from decimal import Decimal
5
----> 6 resultHandler = age.newResultHandler()
7
8 def evalExp(exp):
AttributeError: module 'age' has no attribute 'newResultHandler'
In the other side when I decide to import that from the source code directly it works properly
# Working
import age.drivers.python.age as age
import unittest
from decimal import Decimal
resultHandler = age.newResultHandler()
def evalExp(exp):
value = resultHandler.parse(exp)
print(type(value), "|", exp, " --> " ,value )
mapStr = '{"name": "Smith", "num":123, "yn":true, "bigInt":123456789123456789123456789123456789::numeric}'
evalExp(mapStr)
Output
<class 'dict'> | {"name": "Smith", "num":123, "yn":true, "bigInt":123456789123456789123456789123456789::numeric} --> {'name': 'Smith', 'num': 123, 'yn': True, 'bigInt': Decimal('123456789123456789123456789123456789')}
Notebook link: https://drive.google.com/file/d/1f_6UUHlZbbKeAg4t94s9Hl59-DpSk3jU/view?usp=sharing
Actually replacing
python3 setup.py install
WITH
pip3 install .
For the package installation solving the problem
On the other side if we kept using the first command, the package gets installed at somewhere it is not included in the python system so that we can append that to python packages' paths to look for through
1. Getting where the package is
!pip3 show age
2. Append the path to the sys
import sys
sys.path.append("OUTPUT_OF_STEP_1")
import age