DerwenAI / kglab

Graph Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, NetworkX, RAPIDS, RDFlib, pySHACL, PyVis, morph-kgc, pslpython, pyarrow, etc.
https://derwen.ai/docs/kgl/
MIT License
574 stars 65 forks source link

Bug report: "AttributeError: partially initialized module 'kglab'..." #278

Closed stuchalk closed 1 year ago

stuchalk commented 1 year ago

I'm submitting a bug report.

Current Behaviour:

When I run the code I get: AttributeError: partially initialized module 'kglab' has no attribute 'KnowledgeGraph' (most likely due to a circular import)

Expected Behaviour:

That it would work per the repo readme file

Steps to reproduce:

Snapshot:

kglab

Environment:

Installed packages

aiobotocore              2.4.0
aiohttp                  3.8.3
aioitertools             0.11.0
aiosignal                1.2.0
appnope                  0.1.3
asgiref                  3.5.2
asttokens                2.0.8
async-timeout            4.0.2
attrs                    22.1.0
backcall                 0.2.0
botocore                 1.27.59
cachetools               5.2.0
certifi                  2022.9.24
cffi                     1.15.1
charset-normalizer       2.1.1
chocolate                0.0.2
colorama                 0.4.5
cryptography             38.0.1
csvwlib                  0.3.2
decorator                5.1.1
Django                   4.1.2
elementpath              3.0.2
executing                1.1.1
falcon                   3.1.0
frozenlist               1.3.1
fsspec                   2022.8.2
gcsfs                    2022.8.2
google-api-core          2.10.2
google-auth              2.12.0
google-auth-oauthlib     0.5.3
google-cloud-core        2.3.2
google-cloud-storage     2.5.0
google-crc32c            1.5.0
google-resumable-media   2.4.0
googleapis-common-protos 1.56.4
greenlet                 1.1.3.post0
html5lib                 1.1
icecream                 2.1.3
idna                     3.4
ipython                  8.5.0
isodate                  0.6.1
jedi                     0.18.1
Jinja2                   3.1.2
jmespath                 1.0.1
jsonpath-python          1.0.6
jsonpickle               2.2.0
kglab                    0.6.1
language-tags            1.1.0
MarkupSafe               2.1.1
matplotlib-inline        0.1.6
morph-kgc                2.2.0
multidict                6.0.2
networkx                 2.8.7
numpy                    1.23.3
oauthlib                 3.2.1
owlrl                    6.0.2
oxrdflib                 0.3.2
packaging                21.3
pandas                   1.5.0
parso                    0.8.3
patsy                    0.5.3
pexpect                  4.8.0
pickleshare              0.7.5
pip                      22.2.2
prettytable              2.5.0
prompt-toolkit           3.0.31
protobuf                 4.21.7
pslpython                2.3.0
ptyprocess               0.7.0
pure-eval                0.2.2
pyarrow                  9.0.0
pyasn1                   0.4.8
pyasn1-modules           0.2.8
pycparser                2.21
Pygments                 2.13.0
pynvml                   11.4.1
pyoxigraph               0.3.6
pyparsing                3.0.9
pyshacl                  0.20.0
python-dateutil          2.8.2
pytz                     2022.4
pyvis                    0.3.0
PyYAML                   6.0
rdflib                   6.2.0
rdflib-jsonld            0.6.2
requests                 2.28.1
requests-oauthlib        1.3.1
rsa                      4.9
s3fs                     2022.8.2
scipy                    1.9.2
setuptools               65.4.1
six                      1.16.0
sql-metadata             2.6.0
SQLAlchemy               1.4.41
sqlparse                 0.4.3
stack-data               0.5.1
statsmodels              0.13.2
tqdm                     4.64.1
traitlets                5.4.0
uritemplate              4.1.1
urllib3                  1.26.12
urlpath                  1.2.0
wcwidth                  0.2.5
webencodings             0.5.1
wheel                    0.37.1
wrapt                    1.14.1
yarl                     1.8.1
Mec-iS commented 1 year ago

hi. thanks for using kglab.

Your problem is probably due by the fact that you called your script kglab.py. Please try to change the name of your file to script1.py or test1.py or anything with a different name. Calling the file with the same name of the library can create this problem if your are inside a Python module (any directory with the __init__.py file in it).

Let me know if this fixes.

stuchalk commented 1 year ago

Apologies, this is such a rookie mistake. I'm not a expert but neither am I am noob - I should have checked that. Interestingly now that it is running I am getting another error:

Traceback (most recent call last):
  File "/Users/n00002621/PycharmProjects/chemshapes/chemtwins/kglabexample.py", line 5, in <module>
    kg.load_rdf("https://storage.googleapis.com/kglab-tutorial/foaf.rdf", "xml")
  File "/Users/n00002621/.local/share/virtualenvs/chemshapes-jx7D4Fdy/lib/python3.10/site-packages/kglab/decorators.py", line 66, in wrapper
    bound_arguments = sig.bind(*args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/inspect.py", line 3179, in bind
    return self._bind(args, kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/inspect.py", line 3105, in _bind
    raise TypeError(
TypeError: too many positional arguments

Process finished with exit code 1

Any thoughts?

ceteri commented 1 year ago

Thanks @stuchalk, these are great questions!

It's rather surprising how often that first issue pops up in Py code development. One would think the interpreters/compilers might eventually give better warnings – although since I'm in PSF, I should probably make a PR before complaining :)

For the second issue, we'd need to see your code. Mostly likely it's a simple change to the argument list for a method code, and I'm guessing probably in load_rdf() but we can't see it from the copy/pasted exception text.

stuchalk commented 1 year ago

The same code as before: kglab

ceteri commented 1 year ago

In the code above, the line:

kg.load_rdf("...", "xml")

needs to be:

kg.load_rdf("...", format="xml")

For this call to load_rdf(), the first argument is a "positional argument" and the second argument is a "keyword argument" (aka "kwarg" ) so it requires the format= before the value.

Here's more history and gory details :) https://peps.python.org/pep-0570/#history-of-positional-only-parameter-semantics-in-python

stuchalk commented 1 year ago

OK, I am having one of those days. Close this thing so I don't waste any more of your time. Thanks!

ceteri commented 1 year ago

No worries, great questions. We want to hammer on our docs to get this into shape :) It needs to be intuitive. Many thanks for all your feedback!