rdflib-jsonld
rdflib-jsonld copied to clipboard
py3compat module is removed in rdflib 5.0.0rc1
Finally after more than 3 years of waiting the rdflib 5.0.0 release is nearly upon us!
The 5.0.0rc1 release was pushed out today, and while we've tried to avoid as much breaking as possible, there is inevitably a lot of churn between v4.2.2 in Jan 2017, and today.
We've noticed when importing rdflib-jsonld in RDFLib 5.0.0rc1, we get:
ImportError:
module rdflib.py3compat not found
The py3compat module was removed from rdflib master years ago, but the change hasn't made its way into a release until today.
Is there a way we can make rdflib-jsonld compatible with RDFLib 5.0.0 during the RC period?
The rdflib.py3compat dependency in rdflib-jsonld has been removed from rdflib-jsonld master so a new release from master will fix this.
oh, did I just run into this? https://twitter.com/danbri/status/1247263674080903169
maybe I should install from github?
I've put half an hour into this and totally failed so far. I have no legacy commitments, just want to get rdflib working in a fresh Python 3 (https://colab.research.google.com/) environment. I am super-happy to see these libraries getting attention again and don't wish to seem ungrateful. Looking forward to sample code that shows off everything you've been doing for those of us who haven't managed to follow the details...
Hi @danbri yes, this is the issue you hit! If you just install rdflib-jsonld from master, rather than the current 0.4.0 release, everything will work. We should have a new rdflib-jsonld release out in days to fix this permanently.
I assume you’re running the 5.0.0rc1 Release Candidate for the main rdflib? Because the other option would be to downgrade that to rdflib 4.2.2 (the now 3+ year old stable release!) and that would also fix things for you.
Full rdflib 5.0.0 should be out in 10 or so days, assuming we get this next rdflib-jsonld release out to fix this issue first!
Here is an attempt in Colab. It's from @bquinn but my experiments were essentially the same:
https://colab.research.google.com/drive/1s39p5M5jUBHDf0MNT4xHhjylImm3JrlQ#scrollTo=0FC4rxAwTkcW
He reported that it works some of the time, when you use "run all" rather than run step by step. I partially replicated that experience but am still getting a "no plugin" error at this moment. This is with a python 3 runtime, and I didn't have any success with python 2. Could this be a Colab quirk?
I just released rdflib-jsonld 0.5.0 from current master. I hope that helps sorting this out.
@danbri @bquinn: I'm not familiar with Colab but I've tested each of the code chunks you have in there with this rdflib-jsonld 0.5.0 release and these are my results:
from rdflib import Graph, plugin
from rdflib.serializer import Serializer
Imports work fine.
from rdflib import *
g = ConjunctiveGraph()
g.parse("https://data.hikob.com/osc/parking", format="json-ld")
print(g.serialize())
I can't run this code as I see no data at https://data.hikob.com/osc/parking, hence I get the general urllib exception urllib.error.URLError
.
from rdflib import Graph, plugin
from rdflib.serializer import Serializer
test_json = '''
{
"@context": {
"dc": "http://purl.org/dc/terms/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#"
},
"@id": "http://example.org/about",
"dc:title": {
"@language": "en",
"@value": "Someone's Homepage"
}
}
'''
g = Graph().parse(data=test_json, format='json-ld')
print(g.serialize(format='json-ld', indent=4).decode('utf-8'))
Runs just fine.
Can you please confirm/reject these results and, if confirmed, I will close this Issue since the rdflib-jsonld 0.5.0 release seems to solve it.
Running (rdflib-5.0.0, rdflib-jsonld-0.6.0.dev0, Python 3.6.9) that second block in CoLab I get:
PluginException: No plugin registered for (json-ld, <class 'rdflib.parser.Parser'>)
Details follow.
Library installation was using this:
!pip install git+https://github.com/RDFLib/rdflib.git
!pip install git+https://github.com/RDFLib/rdflib-jsonld.git
... which I assume ought to install the latest/greatest version. Results:
Collecting git+https://github.com/RDFLib/rdflib.git
Cloning https://github.com/RDFLib/rdflib.git to /tmp/pip-req-build-d53z25qi
Running command git clone -q https://github.com/RDFLib/rdflib.git /tmp/pip-req-build-d53z25qi
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from rdflib==5.0.0) (1.12.0)
Collecting isodate
Downloading https://files.pythonhosted.org/packages/9b/9f/b36f7774ff5ea8e428fdcfc4bb332c39ee5b9362ddd3d40d9516a55221b2/isodate-0.6.0-py2.py3-none-any.whl (45kB)
|████████████████████████████████| 51kB 1.7MB/s
Requirement already satisfied: pyparsing in /usr/local/lib/python3.6/dist-packages (from rdflib==5.0.0) (2.4.7)
Building wheels for collected packages: rdflib
Building wheel for rdflib (setup.py) ... done
Created wheel for rdflib: filename=rdflib-5.0.0-cp36-none-any.whl size=231055 sha256=9ffcd48b30131bc767927479812fd6b4b7bb7f9ff54481d6f3e0cbbdaa090850
Stored in directory: /tmp/pip-ephem-wheel-cache-82jadaqf/wheels/1a/f0/e4/9ee2f2ecec43f424d520070864a049604d269348c68b9ce69e
Successfully built rdflib
Installing collected packages: isodate, rdflib
Successfully installed isodate-0.6.0 rdflib-5.0.0
Collecting git+https://github.com/RDFLib/rdflib-jsonld.git
Cloning https://github.com/RDFLib/rdflib-jsonld.git to /tmp/pip-req-build-hgkazorl
Running command git clone -q https://github.com/RDFLib/rdflib-jsonld.git /tmp/pip-req-build-hgkazorl
Requirement already satisfied: rdflib>=4.2.2 in /usr/local/lib/python3.6/dist-packages (from rdflib-jsonld==0.6.0.dev0) (5.0.0)
Requirement already satisfied: isodate in /usr/local/lib/python3.6/dist-packages (from rdflib>=4.2.2->rdflib-jsonld==0.6.0.dev0) (0.6.0)
Requirement already satisfied: pyparsing in /usr/local/lib/python3.6/dist-packages (from rdflib>=4.2.2->rdflib-jsonld==0.6.0.dev0) (2.4.7)
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from rdflib>=4.2.2->rdflib-jsonld==0.6.0.dev0) (1.12.0)
Building wheels for collected packages: rdflib-jsonld
Building wheel for rdflib-jsonld (setup.py) ... done
Created wheel for rdflib-jsonld: filename=rdflib_jsonld-0.6.0.dev0-py2.py3-none-any.whl size=15423 sha256=135a7b1ea4cfaa8131bdf689678173d81a6e8a729b8bbb1b800db2051b1888e6
Stored in directory: /tmp/pip-ephem-wheel-cache-8nhewmeg/wheels/08/aa/f2/b8c64203bdfc4f4d9fc99c4be325c7a4558bd60c4d2ada4d1e
Successfully built rdflib-jsonld
Installing collected packages: rdflib-jsonld
Successfully installed rdflib-jsonld-0.6.0.dev0
Then we try this:
from rdflib import Graph, plugin
from rdflib.serializer import Serializer
test_json = '''
{
"@context": {
"dc": "http://purl.org/dc/terms/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#"
},
"@id": "http://example.org/about",
"dc:title": {
"@language": "en",
"@value": "Someone's Homepage"
}
}
'''
g = Graph().parse(data=test_json, format='json-ld')
print(g.serialize(format='json-ld', indent=4).decode('utf-8'))
Result:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/rdflib/plugin.py in get(name, kind)
102 try:
--> 103 p = _plugins[(name, kind)]
104 except KeyError:
KeyError: ('json-ld', <class 'rdflib.parser.Parser'>)
During handling of the above exception, another exception occurred:
PluginException Traceback (most recent call last)
2 frames
/usr/local/lib/python3.6/dist-packages/rdflib/plugin.py in get(name, kind)
104 except KeyError:
105 raise PluginException(
--> 106 "No plugin registered for (%s, %s)" % (name, kind))
107 return p.getClass()
108
PluginException: No plugin registered for (json-ld, <class 'rdflib.parser.Parser'>)
Version:
import sys
print("Python version")
print (sys.version)
print("Version info.")
print (sys.version_info)
Output:
Python version
3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0]
Version info.
sys.version_info(major=3, minor=6, micro=9, releaselevel='final', serial=0)
While I would suggest that you switch to pypi, the above sequence works for me. It looks like you are using Jupyter -- any chance that you may need to restart it to bet the import to "take"?
I changed the imports to use pypi instead of github and re-started the engine and the above example worked.
Confirming I don't get the issue using the PyPI releases (rdfllib 5.0.0, rdflib-jsonld 0.5.0).
I replicate the issue with rdfllib installed but not rdflib-jsonld.
Hopefully we can bypass all of this by incorporating rdflib-jsonld into rdflib soon...
Thanks for looking into this. I've just tried again (using the same Colaboratory notebook that @danbri linked above) importing the pypi versions now that they have been released:
!pip install rdflib
!pip install rdflib-jsonld
from rdflib import Graph, plugin
from rdflib.serializer import Serializer
If I run the Colaboratory commands "factory reset runtime" and then "run all", I get the same as @danbri:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/rdflib/plugin.py in get(name, kind)
102 try:
--> 103 p = _plugins[(name, kind)]
104 except KeyError:
KeyError: ('json-ld', <class 'rdflib.parser.Parser'>)
During handling of the above exception, another exception occurred:
PluginException Traceback (most recent call last)
2 frames
/usr/local/lib/python3.6/dist-packages/rdflib/plugin.py in get(name, kind)
104 except KeyError:
105 raise PluginException(
--> 106 "No plugin registered for (%s, %s)" % (name, kind))
107 return p.getClass()
108
PluginException: No plugin registered for (json-ld, <class 'rdflib.parser.Parser'>)
BUT, if I then run "restart runtime" (as opposed to "factory reset"), and then "run all" again, it works.
So @hsolbrig's comment about restarting Jupyter to get the import to "take" is on the money. But why should that be the case? Is it a bug in Jupyter or Colaboratory perhaps?
I've reproduced what @bquinn reports. It needed a reset runtime and then a restart runtime to get rdflib to work. However, after the "restart runtime", you don't need to run the installation commands again, it is enough to do this:
from rdflib import Graph, plugin
from rdflib.serializer import Serializer
test_json = '''
{
"@context": {
"dc": "http://purl.org/dc/terms/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#"
},
"@id": "http://example.org/about",
"dc:title": {
"@language": "en",
"@value": "Someone's Homepage"
}
}
'''
g = Graph().parse(data=test_json, format='json-ld')
print(g.serialize(format='json-ld', indent=4).decode('utf-8'))
This looks relevant:
- https://stackoverflow.com/questions/57831187/need-to-restart-runtime-before-import-an-installed-package-in-colab
From the stackoverflow item above, I've found that
import os
os.kill(os.getpid(), 9)
does the job reliably (if horribly), and that a restart does seem to be needed for other Python modules too.
We are now rather beyond the scope of the original issue, but this might be worth remembering if others have Colab / Jupyter problems.