1

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

3 Answers3

1

This error is caused by the antlr package. Try installing another version of antlr4-python3-runtime. In the requirements file, it suggests installing version 4.11.1 but try installing 4.9.2.

pip install antlr4-python3-runtime==4.9.2

This should work and you should be able to use age outside the cloned repo.

You might also need to git pull to check if the attribute name has been changed (I noticed that in one of the notebooks).

Tito
  • 289
  • 8
  • Not solving the problem it issued something actually regarding the version changes there is some missing stuff caused some errors – Mohamed Mokhtar - rrrokhtar Apr 27 '23 at 12:05
  • Can you share more details on the "missing stuff causing some errors"?. I see you installed via the source code. However, you can consider installing via **PyPi**: `pip install apache-age-python` Then check for the version of `antlr4-python3-runtime` installed `pip list | grep antlr4` if its version `4.11.1`, you need to uninstall it and install `4.9.2` `pip uninstall antlr4-python3-runtime==4.11.1` `pip install antlr4-python3-runtime==4.9.2` – Tito Apr 27 '23 at 15:17
  • apache-age-python comes from https://github.com/rhizome-ai/apache-age-python which I think is different source from that we are looking, after installation of antlr4 4.9.2 I got the following issue when I tried to install the package using python3 setup.py install I get that: File "/usr/local/lib/python3.10/dist-packages/antlr4/atn/ATNDeserializer.py", line 89, in adjust v = ord(c) TypeError: ord() expected string of length 1, but int found Full output can be seen through the notebook also. – Mohamed Mokhtar - rrrokhtar Apr 27 '23 at 17:32
  • I have added an answer that solves the problem on the environment, you can check that out – Mohamed Mokhtar - rrrokhtar Apr 27 '23 at 17:33
0

I think you are creating the py file outside the github repo. That's why the 'age' you are mentioning in your not-working file, is not a valid python package.

To fix this create the same file in age/drivers/python/ directory and try to run the file. This time the 'age' mentioned will use the package inside age/drivers/python/age.

  • Actually I have setup it as a pip package so it doesn't matter where my python script or the notebook is. – Mohamed Mokhtar - rrrokhtar Apr 26 '23 at 09:32
  • When This is working Its using a path of age.... So please check if your notebook is not using the same compailer as you you installed pip package.. Or try that using .py file..... and compile it in same environment where you installed pip.. I have tested it in my environment. Its working fine – Moontasir Mahmood Apr 26 '23 at 11:52
0

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